C#编写一个计算器,要求输入带有运算符的式子如1+1,3*4这类的,求提供一下代码,参考一下





//A.要求用户在表格中提供公式
//[INT][OPERATOR][INT]
//例如“1+1”或“3*4”或“160/40//B.提取2个数字字符串和运算符。
//2个数字字符串转换为实际数字。
//明智地选择类型!
//C.计算并显示结果

using System;

namespace advance_calculator
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a formula in the form [INT][OPERATOR][INT]:");
            String strInput = Console.ReadLine();
            string tempnum = "";
            string tempoperator = "";
            foreach (char c in strInput)
            {
                if (c >= '0' && c <= '9')
                {
                    tempnum += c;
                }
                else if(c=='+'||c=='-'||c=='*'||c=='/')
                {
                    tempoperator += c;
                }

            }
            //int num1 = Convert.ToInt32(strInput);
            //int num2 = Convert.ToInt32(strInput);
            //String type = strInput;
            int result = 0;

            //if (type == "+")
            //{
            //    result = num1 + num2;
            //}
            //else if (type == "-")
            //{
            //    result = num1 - num2;
            //}
            //else if (type == "*")
            //{
            //    result = num1 * num2;
            //}
            //else if (type == "/")
            //{
            //    result = num1 / num2;
            //}
            Console.WriteLine($"The result is {result}");
        }

    }     
}