private static void Delegates() { CustomerManager customerManager = new CustomerManager(); customerManager.SendMessage(); customerManager.ShowAlert(); MyDelegate myDelegate = customerManager.SendMessage; myDelegate += customerManager.ShowAlert; myDelegate -= customerManager.SendMessage; myDelegate(); MyDelegate2 myDelegate2 = customerManager.SendMessage2; myDelegate2 += customerManager.ShowAlert2; myDelegate2("Hello"); Matematik matematik = new Matematik(); MyDelegate3 myDelegate3 = matematik.Topla; myDelegate3 += matematik.Carp; Console.WriteLine(myDelegate3(2, 3)); Console.ReadLine(); }
private static void Func() { Matematik matematik = new Matematik(); Console.WriteLine(matematik.Topla(5, 6)); Func <int, int, int> add = matematik.Topla; Console.WriteLine(add(10, 12)); Func <int> getRandomNumber = delegate() { Random random = new Random(); return(random.Next(1, 100)); }; Console.WriteLine(getRandomNumber()); Thread.Sleep(1000); Func <int> getRandomNumber2 = () => new Random().Next(1, 100); Console.WriteLine(getRandomNumber2()); }