我有一字符串例如:
string _strvalue = "(8+2)/2 +4";
我想最后能算出它的值9
我想计算它在C#里头怎么表示

解决方案 »

  1.   

    string _strvalue = ((8+2)/2 +4).ToString();
      

  2.   

    还(不行)
    我的意思我的的字符串
    string _strvalue = "(8+2)/2 +4";我想最后能计算strvalue的值行不
      

  3.   

    你是要对string_strvalue再计算吗?
    如果是可以转换成其他类型再计算
    string _strvalue = ((8+2)/2 +4).ToString();
    string_strvalue_new=(Convert.ToDouble(string _strvalue)/3).ToString();
      

  4.   

    this.textBox1.Text=Convert.ToInt32((8+2)/2+4).ToString();
      

  5.   

    引用:Microsoft.Vsa.dll
    引用:Microsoft.JScript.dllpublic static object EvalExpression(string strExpression)
    {
        Microsoft.JScript.Vsa.VsaEngine engine = 
            Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
        return Microsoft.JScript.Eval.JScriptEvaluate(strExpression, engine);
    }调用:
    int ret = (int)EvalExpression("(8+2)/2+4"); // 9
      

  6.   

    我的变量可能是 string _strvalue = "(8+2)/2 +4";
    也可能是_strvalue = "(1+1)/1 +1";
    也可能是别的合法的可计算的组合
    我只是想把它计算出来,(事先是未知的)hchxxzx明白了我的意思了,但我想应该有一个函数就可能实现了,
    我在别的语言实现过了