你是要做一个类似于Windows附带的计算器的还是直接输入表达式进行计算的? 第一种简单,无非就是做一些按钮并执行制定操作而已。 第二种我写了两份,分别使用正则表达式和语法分析技术 使用正则表达式的: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; using System.Drawing; namespace Eval { public class EvalEventArgs : EventArgs { public EvalEventArgs(string Expressions) { this.Expressions = Expressions; } public string Expressions { get; set; } public string Message { get; set; } } public class Function { static Regex Num = new Regex(@"(\-?\d+\.?\d*)"); static Regex Power = new Regex(Num.ToString() + @"\^" + Num.ToString()); static Regex AddSub = new Regex(Num.ToString() + "([+-])" + Num.ToString()); static Regex MulDiv = new Regex(Num.ToString() + "([*/])" + Num.ToString()); static Regex AndXor = new Regex(Num.ToString() + "(and|xor)" + Num.ToString()); static Regex InnerRegex = new Regex(@"\([^\(\)]+\)"); static Regex FunctionRegex = new Regex(@"(ln|lg|sin|cos|tan|ctg|sh|ch|th|arcsin|arccos|arctan|not)" +Num.ToString()); static Regex LBrackets = new Regex(@"\{|\["); static Regex RBrackets = new Regex(@"\}|\]"); const double PI = Math.PI; const double e = Math.E; public event EventHandler Evaling; public event EventHandler EvalComplent; public event EventHandler Error; private void OnError(string Expressions, string Message) { if (Error != null) Error(this, new EvalEventArgs(Expressions) { Message = Message }); IsAbort = true; } private bool IsAbort = false;