using System;
using System.Collections;
using System.Text;
namespace ExpresstionClass
{
public class ExpresstionClass
{
public string Expresstion;//String类型表达式
public ExpresstionClass()
{
}
public ExpresstionClass(string expresstion)
{
this.Expresstion = expresstion;
}
// 判断字符串是否为数值
public bool IsNumberExp(string str)
{
bool isnumeric = false;
byte c;
if (str == null || str.Length == 0)
return false;
System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
byte[] bytestr = ascii.GetBytes(str);
for (int i = 0; i < bytestr.Length; i++)
{
c = bytestr[i];
if ((c >= 48 && c <= 57) || c == 46)
{
isnumeric = true; ;
}
else
{
if (c == 45 && bytestr .Length > 1)
{
isnumeric = true;
}
else
{
isnumeric = false;
break;
}
}
}
return isnumeric;
}
// 基本一目计算
public double account(double n1, double n2, string num_op)
{
double aresult = 0;
switch (num_op)
{
case "+":
aresult = n1 + n2;

这是一个使用C#编写的类,名为ExpresstionClass,用于处理包含括号在内的四则运算。类中包含了判断字符串是否为数值的方法,将中缀表达式转换为后缀表达式,以及计算后缀表达式值的功能。通过操作数和运算符的ArrayList,实现了表达式的计算逻辑。

2371

被折叠的 条评论
为什么被折叠?



