设计一个控制台应用程序项目,通过委托方式求两个整数的和差积商模

[C#]

设计一个控制台应用程序项目,通过委托方式求两个整数的和差积商模

namespace Computer
{
    //定义委托
    public delegate void ComputerDelegate(int num1,int num2);
    class Program
    {
        private static void AddOut(int num1,int num2)
        {
            Console.WriteLine("{0}+{1}={2}" , num1,num2,num1+num2);
        }
        private static void ReduceOut(int num1, int num2)
        {
            Console.WriteLine("{0}-{1}={2}", num1, num2, num1 - num2);
        }
        private static void MultiplyOut(int num1, int num2)
        {
            Console.WriteLine("{0}*{1}={2}", num1, num2, num1*num2);
        }
        private static void DivideOut(int num1, int num2)
        {
            Console.WriteLine("{0}/{1}={2}", num1, num2, num1 / num2);
        }
        private static void ModuleOut(int num1, int num2)
        {
            Console.WriteLine("{0}%{1}={2}", num1, num2, num1 % num2);
        }
        private static void outString(int num1,int num2, ComputerDelegate  NumOut)
        {
            NumOut(num1,num2);
            }
        static void Main(string[] args)
        {
            ComputerDelegate delegate1 = new ComputerDelegate(AddOut);
            delegate1 += ReduceOut;
            delegate1 = delegate1 + MultiplyOut;
            delegate1 += DivideOut;
            delegate1 = delegate1 + ModuleOut;
            outString(4,2, delegate1);

            Console.WriteLine();
            delegate1 -= ReduceOut;
            delegate1 = delegate1 - MultiplyOut;
            delegate1 -= DivideOut;
            delegate1 = delegate1 - ModuleOut;
            outString(4, 2, delegate1);
            Console.ReadKey();
        }
    }
}

实现效果:
设计一个控制台应用程序项目,通过委托方式求两个整数的和差积商模_第1张图片

你可能感兴趣的:(C#)