Is there an eval function In C#?

前端 未结 7 1935
[愿得一人]
[愿得一人] 2020-12-05 03:41

I\'m typing an equation into a TextBox that will generate the graph of the given parabola. Is it possible to use an eval function? I\'m using C# 2010 and it doesn\'t have Mi

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 03:58

    Thank you so much Mr.Teoman Soygul

    if you want to catch the error then you can use try catch,then we can use that values to future purpose.

    try
    {
        DataTable table = new System.Data.DataTable();
        table.Columns.Add("expression", string.Empty.GetType(), expression);
        DataRow row = table.NewRow();
        table.Rows.Add(row);
        return double.Parse((string)row["expression"]);
    }
    catch (Exception)
    {
        return -1;
    }
    

提交回复
热议问题