JustTemp
JustTemp

Reputation: 75

How to convert a condition string to a boolean format?

I taught myself C#. I'm stuck on the following. How do I convert a condition string to a boolean format?

string ConditionString = "1 > 2";
bool Judgment = Convert.ToBoolean(ConditionString); //Error
textBox1.Text = Convert.ToString(Judgment);

Upvotes: 1

Views: 1670

Answers (1)

Sajad Afaghiy
Sajad Afaghiy

Reputation: 596

You can use this block of code (in System.Data namespace):

DataTable dt = new DataTable();
bool judgment = Convert.ToBoolean(dt.Compute("1 > 2", null));

that give you a result as true or false.

Upvotes: 1

Related Questions