Is there a string math evaluator in .NET?

前端 未结 16 1452
长情又很酷
长情又很酷 2020-11-22 01:01

If I have a string with a valid math expression such as:

String s = \"1 + 2 * 7\";

Is there a built in library/function in .NET that will p

16条回答
  •  自闭症患者
    2020-11-22 01:31

    If you need very simple thing you can use the DataTable :-)

    Dim dt As New DataTable
    dt.Columns.Add("A", GetType(Integer))
    dt.Columns.Add("B", GetType(Integer))
    dt.Columns.Add("C", GetType(Integer))
    dt.Rows.Add(New Object() {12, 13, DBNull.Value})
    
    Dim boolResult As Boolean = dt.Select("A>B-2").Length > 0
    
    dt.Columns.Add("result", GetType(Integer), "A+B*2+ISNULL(C,0)")
    Dim valResult As Object = dt.Rows(0)("result")
    

提交回复
热议问题