C # .NET 4.0 eval expression

Possible duplicates:
equivalent to C # equivalent?
How can I evaluate a C # expression dynamically?

How can I evaluate valid C # code and get results inside a compiled program (dynamically)? I know this is not very clear, I will try to show this using a piece of code:

Visual C # 2010.

double x = 3.0;//this is function argument, we'll take 3
string str = "Math.Pow(x,2)+2*x+4";//value with written function in C#,equals: x^2+2x+4
double y = eval(str);
/* this is the idea! something like JS.I want to make string parsed into parameter,i.e
y=19 - this is what double y should became after eval(str) */

Hope you have an idea.

Thank.

+3
source share
1 answer

No, LINQ will not do this for you.

CSharpCodeProvider, , , , .

+1

Source: https://habr.com/ru/post/1774463/


All Articles