static void Main(string[] args)
        {
            // Assign type Method1Delegate to variable delegate1 and point it to Method1.
            Method1Delegate delegate1 = Method1;

            delegate1();

            // Assign type Method2Delegate to variable delegate2 and point it to Method2.
            Method2Delegate delegate2 = Method2;

            Console.WriteLine("Method 2 float value " + delegate2());

            // Assign type Method3Delegate to variable delegate3 and point it to Method3.
            Method3Delegate delegate3 = Method3;

            delegate3("Andreas", 25, 1.82f);

            // Create a new instance of Math class.
            Math mathObject = new Math();
            // Assign type MathDelegate to variable math and point it to Addition method in Math class.
            MathDelegate math = mathObject.Addition;

            Console.WriteLine("Addition 17 + 18 = " + math(17, 18));
            // Assign math variable to Multiplication method in Math class.
            math = mathObject.Multiplication;
            Console.WriteLine("Multiplication 3 * 7 = " + math(3, 7));

            // Assign type MyDelegate to variable myDelegate and point it to Method4.
            MyDelegate myDelegate = Method4;

            // Assign another method to myDelegate
            myDelegate += Method5;
            // Invoke myDelegate, it will call both Method4 and Method5.
            myDelegate();

            // Assign type IntDelegate to variable addition and point it to Lambda Expression
            IntDelegate addition = (num1, num2) => num1 + num2;

            Console.WriteLine("Addition 13 + 4 = " + addition(13, 4));
            // Assign type IntDelegate to variable subtraction and point it to Lambda Expression
            IntDelegate subtraction = (num1, num2) => num1 - num2;

            Console.WriteLine("Subtraction 8 - 2 = " + subtraction(8, 2));
            // Assign type IntDelegate to variable subtraction and point it to Lambda Expression
            FloatDelegate multiplication = (num1, num2) => num1 * num2;

            Console.WriteLine("Multiplication 4.2 * 3.1 = " + multiplication(4.2f, 3.1f));
            // Assign type IntDelegate to variable division and point it to Lambda Expression
            FloatDelegate division = (num1, num2) => num1 / num2;

            Console.WriteLine("Multiplication 4 / 32 = " + division(4, 32));
        }
Example #2
0
 public NativeFooWrapper(IntPtr self, Method1Delegate method1, Method2Delegate method2)
 {
     this._self    = self;
     this._method1 = method1;
     this._method2 = method2;
 }