I would like to know if an expression can be used as a parameter / parameter in C #. I would like to do something like this:
int x = 0;
public void g()
{
bool greaterThan = f("x>2");
bool lessThan = f("x<2");
}
public bool f(Expression expression)
{
if(expression)
return true;
else
return false;
}
Here is what I do not want to do:
int x = 0;
public void g()
{
bool greaterThan = f(x, '<', 2);
}
public bool f(int x, char c, int y)
{
if(c == '<')
return x < y;
if(c == '>')
return x > y;
}
In fact, what I get is a way to get around using a switch or a series of if statements for each of: <> <=> = ==! =. Is there any way to do this?
Edit: Suppose the expression is a string such as "x <2". Is there a way to go from a string to a predicate without using a series of if statements from the condition?
source
share