Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,
Is it possible in c#.............

string a = "10";
string b = 20;
string c = 40;

k="a*b+c";
m="a+b+c";
n="a*b*c"
string output = evaluate(k) // output =240

string output = evaluate(m) // output =70

string output = evaluate(n) // output =800

if yes please help me how do this in c#...
variable are declared at runtime
and formula of k,m,n is sroted in database. and fetch at runtime.
=============================

actually the real scenario is as :- i have several variables stored in table.
table1:fieldmaster
field_name | field_type | field_length
ab varchar 20
bc varchar 20
ca varchar 20
and i fetch all field_name in a table.
and took a dictionary and add field_name as dictionary key.
and in for loop assign values to each key
----
now in other table i have some formula which evaluate fields.
table2 : formulamast
field_name | formula
ca | ab+(bc*bc)
now i have to evaluate values of ca according to formula which is in formula table.
Posted
Updated 28-Jan-15 1:53am
v3
Comments
Member 8083455 28-Jan-15 7:55am    
thanks for support.. but it solve if i have integer, but i have string.
now i have updated my question to clear it.

 
Share this answer
 
Please try below code

C#
try
{
    string Expr = "(1+1+1)*1";
    var result = new DataTable().Compute(Expr, null);

}
catch { }



Hope this will solve your purpose.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900