日期:2014-05-20  浏览次数:20958 次

怎样将一个字符串转换为运算符?
是这样的,我想通过参数传递如 "> , <,> = "的表示运算符的字符串,然后在函数中直接将该运算符参与运算,不知大家有没有比较好的方法?先谢谢了

------解决方案--------------------
See
http://community.csdn.net/Expert/TopicView3.asp?id=5370108
------解决方案--------------------
/// <summary>
/// 计算一个表达式的结果
/// </summary>
/// <param name= "expression "> 表达式 </param>
/// <returns> </returns>
public static object Eval(string expression)
{
System.Data.DataTable table = new System.Data.DataTable();
System.Data.DataColumn Col = new System.Data.DataColumn( "col1 ", typeof(string), expression);
table.Columns.Add(Col);

table.Rows.Add(new object[] { " " });
return table.Rows[0][0];
}