Beispiel #1
0
        static void Main(string[] args)
        {
            CustomerManager customerManager = new CustomerManager();
            Mydelegate      myDelegate      = customerManager.SendMessage;

            myDelegate += customerManager.ShowAlert;

            Mydelegate2 mydelegate2 = customerManager.SendMessage;


            //ard arda çalışmasını istediğin metotlar grubu için delegate'leri kullanabilirsiniz.Örneğin bir yemek
            //yapmak için sırasıyla yapılan işlemleri bir metot olarak tanımlayıp hepsini delegate değişkenine atarsak
            //sadece delegate metotunu çağırmamız yeterli olacaktır.
            DortIslem dortIslem = new DortIslem();


            Mydelegate3 mydelegate3 = dortIslem.Carp;

            mydelegate3 += dortIslem.Topla;

            myDelegate();
            mydelegate2("Selamunaleyküm");
            mydelegate3(2, 4);

            Console.Read();
        }
Beispiel #2
0
        _Delegats2()
        {
            Mydelegate2 mydelegate2 = new Mydelegate2(Myclass2.Method2);

            Console.WriteLine(mydelegate2.Invoke("Mico"));

            Console.WriteLine(mydelegate2("Judi"));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //delegate
            //람다식 사용 안한 경우
            Mydelegate cal = delegate(int a, int b)
            {
                return(a + b);
            };

            Console.WriteLine(cal(1, 2));


            //람다식 사용
            Mydelegate cal2 = (a, b) => a + b;

            Console.WriteLine(cal2(1, 2));


            //문 형식 람다식
            Mydelegate2 Compare = (a, b) =>
            {
                if (a > b)
                {
                    Console.WriteLine("{0}보다 {1}가 크다", b, a);
                }
                else if (a > b)
                {
                    Console.WriteLine("{0}보다 {1}가 크다", a, b);
                }
                else
                {
                    Console.WriteLine("{0}, {1}는 같다", a, b);
                }
            };

            Compare(3, 4);

            //Action
            Action <int> act = (int a) => Console.WriteLine(a);

            //Func
            Func <int, int> func = (int a) => a * 2;

            Console.WriteLine(func(4));

            Console.ReadLine();
        }
Beispiel #4
0
 public static Mydelegat1 Method(Mydelegate2 mydelegate2, Mydelegate3 mydelegate3)
 {
     return(delegate { return mydelegate2.Invoke() + mydelegate3.Invoke(); });
 }