C#起一些代码方法被,去念C#委托

先期来瞧下面一个好像中的组成部分艺术:
C# 1

 

C# 2C# 3

 class Bc
    {
        public double Add(double number1, double number2)
        {
            return number1 + number2;
        }

        public double Multiply(double number1, double number2)
        {
            return number1 * number2;
        }

        public double Subtract(double number1, double number2)
        {
            return number1 - number2;
        }

        public double Division(double number1, double number2)
        {
            return number1 / number2;
        }
    }

Source Code

 

使委托来采取:
C# 4

 

C# 5C# 6

class Bd
    {
        public delegate double CalcResult(double number1, double number2);
        public void TestDelegate()
        {
            Bc objBc = new Bc();

            CalcResult obj = new CalcResult(objBc.Multiply);
            Console.WriteLine(obj(2, 5));
        }
    }

Source Code

 

每当支配高运行:

C# 7

  

相关文章