Beispiel #1
0
        private static void LambdaExample1()
        {
            Sum3Numbers sumFunc = (x, y, z) => x + y + z;

            int result = sumFunc.Invoke(10, 20, 30);

            Console.WriteLine(result);
        }
Beispiel #2
0
        private static void DefineAndInitializeDelegates()
        {
            // Ex1: init delegate with a static function
            // Sum3Numbers sumFunc = Sum;

            // Ex2: init delegate with an instance function
            // MathHelper helper = new MathHelper();
            // Sum3Numbers sumFunc = helper.Sum;

            // Ex3: init delegate with an anonimous function
            Sum3Numbers sumFunc = delegate(int x, int y, int z)
            {
                return(x + y + z);
            };

            int result = sumFunc.Invoke(10, 20, 30);

            Console.WriteLine(result);
        }