实现两数之间的运算

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string strResult = "";
            try
            {
                Console.WriteLine("请输入数字A:");
                string strNumberA = Console.ReadLine();
                Console.WriteLine("请输入操作运算符(+、-、*、/):");
                string strOperate = Console.ReadLine();
                Console.WriteLine("请输入数字B:");
                string strNumberB = Console.ReadLine();
                switch(strOperate)
                {
                    case "+":
                        strResult = Convert.ToString(Convert.ToDouble(strNumberA) + Convert.ToDouble(strNumberB));
                        break;
                    case "-":
                        strResult = Convert.ToString(Convert.ToDouble(strNumberA) - Convert.ToDouble(strNumberB));
                        break;
                    case "*":
                        strResult = Convert.ToString(Convert.ToDouble(strNumberA) * Convert.ToDouble(strNumberB));
                        break;
                    case"/":
                        if(strNumberB!="0")
                        {
                        strResult = Convert.ToString(Convert.ToDouble(strNumberA) / Convert.ToDouble(strNumberB));
                        }
                        else
                        {
                            strNumberB="除数不能为0";
                        }
                        break;
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("输入代码不规范:" +ex.Message);
            }
            Console.WriteLine("结果是:" + strResult);
            Console.ReadLine();
        }
    }
}
原文地址:https://www.cnblogs.com/lqsilly/p/2917613.html