Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in c#: expression evaluation function like flash script

Tags:

c#

eval

Duplicate of: How can I evaluate a C# expression dynamically?

See also: C# eval equivalent?

How to evaluate expression. Maybe like:

int a=1;
int b=3;
int c=Eval("a+b");

or

int c=int.parse("1+3*(2+3)");

This seems stupid to me. is it possible in c#?

like image 411
ebattulga Avatar asked Jan 24 '23 20:01

ebattulga


1 Answers

You can take code, and using the CSharpCodeProvider write an Eval function that actually compiles your code into an in-memory assembly and then executes that code.

See this CodeProject article for sample source.

like image 73
joshperry Avatar answered Jan 29 '23 11:01

joshperry