using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Lambda01
{
    // 1. Delegat und Delegaten-Methode
    delegate int myDelegate(int i, int j);

    public class Program
    {
        public static void Main(string[] args)
        {
            SmartCalc calc = new SmartCalc();

            myDelegate add = new myDelegate(calc.Add);
            Console.WriteLine("{0}", add(3, 4).ToString());

            Console.ReadLine();
        }
    }

    public class SmartCalc
    {
        public int Add(int i, int j)
        {
            return i + j;
        }
    }
    

    /* 2. Delegat und anonyme Methode
    delegate int myDelegate(int i, int j);

    public class Program
    {
        public static void Main(string[] args)
        {
            myDelegate add = delegate(int i, int j)
            {
                return i + j;
            };

            Console.WriteLine("{0}", add(3, 4).ToString());

            Console.ReadLine();
        }
    }
    */

    /* 3. Delegaten als Parameter
    public delegate int myDelegate(int i, int j);

    public class Program
    {
        public static void Main(string[] args)
        {
            myDelegate add = delegate(int i, int j)
            {
                return i + j;
            };

            Exec(add);

            Console.ReadLine();
        }

        public static void Exec(myDelegate del)
        {
            Console.WriteLine("{0}", del(3, 4).ToString());
        }
    }
    */


    /* 4. Lambda-Ausdruck
    delegate int myDelegate(int i, int j);

    public class Program
    {
        public static void Main(string[] args)
        {
            myDelegate add = (int i, int j) => { return i + j; };

            Console.WriteLine("{0}", add(3, 4).ToString());

            Console.ReadLine();
        }
    }
    */


    /* 5. Lambda-Ausdruck in vereinfachter Syntax
    delegate int myDelegate(int i, int j);

    public class Program
    {
        public static void Main(string[] args)
        {
            myDelegate add = (i, j) => i + j;

            Console.WriteLine("{0}", add(3, 4).ToString());

            Console.ReadLine();
        }
    }
    */
}