예제 #1
0
        static void Main2(string[] args)
        {
            MyMath         m1 = new MyMath();
            MyMathDelegate d1 = new MyMathDelegate(m1.Addition);

            Console.WriteLine(d1(10, 20));
        }
예제 #2
0
        public void MulticastDelegateReturnValueTest()
        {
            MyMathDelegate doubleMe = (int num) =>
            {
                return(num * 2);
            };

            MyMathDelegate powMe = (int num) => (int)Math.Pow(num, 2);

            MyMathDelegate myDoubleMe = doubleMe;

            myDoubleMe(4).Should().Be(8);

            MyMathDelegate myPowMe = powMe;

            myPowMe(4).Should().Be(16);

            MyMathDelegate myAccumulator = doubleMe;

            myAccumulator += powMe;
            myAccumulator(4).Should().Be(16); // not 64

            MyMathDelegate myAccumulator2 = doubleMe;

            myAccumulator2 += doubleMe;
            myAccumulator2(4).Should().Be(8); // not 16

            //acc += powMe;

            //acc(2).Should().Be(16);

            //acc -= doubleMe;

            //acc(10).Should().Be(100);
        }
예제 #3
0
        static void Main3()
        {
            MyDelegate d1 = new MyDelegate(f1);
            MyMath m1 = new MyMath();
            MyMathDelegate d2 = new MyMathDelegate(m1.Addition);
            d2 += m1.Subtraction;
            d2 += m1.Multiplication;
            //Multicast delegate

            Test(d1, d2);
        }
예제 #4
0
 static void Main()
 {
     MyMath m1 = new MyMath();
     MyMathDelegate d1 = new MyMathDelegate(m1.Addition);
     MyMathDelegate d2 = new MyMathDelegate(m1.Subtraction);
     MyMathDelegate d3 = new MyMathDelegate(m1.Multiplication);
     e2 += d1;
     e2 += d2;
     e2 += d3;
     Console.WriteLine(e2(10, 20));
 }
예제 #5
0
        static void Main()
        {
            MyMath         m1 = new MyMath();
            MyMathDelegate d1 = new MyMathDelegate(m1.Addition);
            MyMathDelegate d2 = new MyMathDelegate(m1.Subtraction);
            MyMathDelegate d3 = new MyMathDelegate(m1.Multiplication);

            e2 += d1;
            e2 += d2;
            e2 += d3;
            Console.WriteLine(e2(10, 20));
        }
예제 #6
0
        static void Main3()
        {
            MyDelegate     d1 = new MyDelegate(f1);
            MyMath         m1 = new MyMath();
            MyMathDelegate d2 = new MyMathDelegate(m1.Addition);

            d2 += m1.Subtraction;
            d2 += m1.Multiplication;
            //Multicast delegate


            Test(d1, d2);
        }
예제 #7
0
        public static void Example2()
        {
            MyMathDelegate mathDelegate = new MyMathDelegate(MathUtility.Add);
            int            num1         = 10;
            int            num2         = 20;

            Console.WriteLine("Add({0}, {1}) = {2}", num1, num2, mathDelegate(num1, num2));

            // Assign the Subract method reference to the delegate object.
            mathDelegate = MathUtility.Subtract;
            Console.WriteLine("Subtract({0}, {1}) = {2}", num1, num2, mathDelegate(num1, num2));

            // Assign the Multiply method reference to the delegate object.
            mathDelegate = MathUtility.Multiply;
            Console.WriteLine("Multiply({0}, {1}) = {2}", num1, num2, mathDelegate(num1, num2));
        }
예제 #8
0
 static void Test(MyDelegate x, MyMathDelegate y)
 {
     x();
     Console.WriteLine(y(10, 20));
 }
예제 #9
0
 static void Main2(string[] args)
 {
     MyMath m1 = new MyMath();
     MyMathDelegate d1 = new MyMathDelegate(m1.Addition);
     Console.WriteLine(d1(10, 20));
 }
예제 #10
0
 static void Test(MyDelegate x, MyMathDelegate y)
 {
     x();
     Console.WriteLine(y(10, 20));
 }