As far as I know, there is nothing built-in that will do that (unless you
want to dynamically create an assembly, class, method and return the object
result of that (PITA if you ask me).

You can also make a jscript dll like so:

[eval.js]
class EvalClass
{
        function Evaluate(expression: String)
        {
                return eval(expression);
        }
}

Compile with jsc /t:library eval.js

Then just reference this dll and Microsoft.Jscript, and you'll have access
to it like so:

EvalClass c = new EvalClass();
int result = (int) c.Evaluate("(10 / 2) * 3");
Console.WriteLine(result);

Adam..

-----Original Message-----
From: Aaron Fanetti [mailto:[EMAIL PROTECTED]]
Sent: Saturday, April 13, 2002 11:47 PM
To: [EMAIL PROTECTED]
Subject: [DOTNET] Evaluate math expression strings?


Does the framework have (or is someone willing to share :) ) a utility class
to do this? Or will I need to build my own interpreter? Something like...

int result = MyMath.Evaluate( "(10 / 2) * 3" );

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to