I have a textbox where i want to read user-input mathematical functions( ex: Math.Sqrt(x) etc).
The code I’ve been using for console testing the function is
static double f(double x)
{
double f;
f = Math.Sqrt(x);
return f;
}
I’m not sure how to modify it: do I read the textbox contents in a string, and add that string as a second argument to the f function ( static double f(double x, string s)? what type of parsing should I apply to the string?
There are several formula parsers out there that you can use.
Basically you need someone/something that evaluates your formula.
I’m using this one successfully in my own projects. It allows for calling it like
What I would not recommend to use is the dynamic compilation of C# code since it adds each compiled code to your application domain (“app domain”) and there is no option to unload it again. (Correct me, if I’m wrong).