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

  

相关文章