用C#写的四则运算类(包括括号运算)

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

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

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值