如何将条件字符串转换为布尔格式?

How to convert a condition string to a boolean format?

我自学了 C#。我坚持以下。如何将条件字符串转换为布尔格式?

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

您可以使用此代码块(在 System.Data 命名空间中):

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

结果为 truefalse