c# 执行数学表达式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            // var  a= 10*1000-90+20
            //加+、减-、乘*、除/、英文状态括号()
            //求余数%、移位运算<<、移位运算>>、位与&、位或|、位异或^、次方Math.pow(3,2)、开方Math.sqrt(81)、求整数parseInt(3.12),以及一些其他JavaScript数学公式
            var expression = "10*1000-90+20/10+10<<2+Math.sqrt(81)";
            var e = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
            try
            {
                object returnValue = Microsoft.JScript.Eval.JScriptEvaluate(expression, e);
                if (returnValue != null && double.TryParse(returnValue.ToString(), out double x))
                {
                var    newValue = returnValue.ToString();
                }
            }
            catch (Exception)
            {
            }

        }
    }
}
原文地址:https://www.cnblogs.com/congqiandehoulai/p/12725757.html