我想问可以用static函数做吗?

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace test
    {
        class Program
        {
            static void Main(string[] args)
            {
            label:
                Console.WriteLine("请逐一的输入你要计算的数字与运算符:");
                int a=Convert.ToInt32( Console.ReadLine());
             char sign = Convert.ToChar(Console.ReadLine());
             int b= Convert.ToInt32(Console.ReadLine());
             Console.Clear();
             Console.WriteLine("输出的结果为:");
             switch (sign)
             { 
                 case '+':
                     int c = Compute1(a, b);
                     Console.WriteLine("{0}+{1}={2}",a,b,c);
                     break;
                 case '-':
                      c = Compute2(a, b);
                      Console.WriteLine("{0}-{1}={2}", a, b, c);
                     break;
                 case '*':
                     c = Compute3(a, b);
                     Console.WriteLine("{0}*{1}={2}", a, b, c);
                     break;
                 case '/':
                    c = Compute4(a, b);
                    Console.WriteLine("{0}/{1}={2}", a, b, c);
                     break;
                 default:
                         Console.Clear();
                         Console.WriteLine("您输入的数据不正确,请重新输入一次.....");
                         break;
                     
             }
             goto label;
                    //Console.ReadKey();
            }        static int Compute1(int i, int j)
            {
                return i + j;
            }
            static int Compute2(int i, int j)
            {
                return i - j;
            }
            static int Compute3(int i, int j)
            {
                return i * j;
            }
            static int Compute4(int i, int j)
            {
                return i / j;
            }    }
    }
    我已经想出...唉