public WebMailClient(MailAccount mail) { this.Account = mail; Account.Received += Account_Received; //подписка на событие Account.Received += (s, m) => { Console.WriteLine($"Web-clien {m.Author} {m.Subject}"); }; //подписка на событие лямбда выражением }
static void Main(string[] args) { Console.WriteLine("Дегаты и события"); Operation sum = Sum;//объявление и инициализация переменной типа делегата Operation div = Div; Operation an = delegate(int x, int y) { return(x * y); }; Operation lamba = (x, y) => x / y; Procudure p = () => Console.WriteLine("This is procedure"); //передеча в параметр метода переменной типа делегата Calculation(5, 4, sum); Calculation(-5, -4, div); Console.WriteLine(an(2, 3)); MailAccount account = new MailAccount(); WebMailClient webClient = new WebMailClient(account); MobileMailClient mobileClient = new MobileMailClient(account); account.Send(new Message { Author = "Ivan", Subject = "Test", Body = "Hi!!!" }); account.Receive(new Message { Author = "Ivan", Subject = "Re:Test", Body = "Hello!!!" }); int?age = null; if (age.HasValue) { Console.WriteLine(age.Value); } else { Console.WriteLine("Value is null"); } Console.WriteLine(age ?? -9999); age = 55; Console.WriteLine(age ?? -9999); Nullable <int> age2 = null; }
public MobileMailClient(MailAccount account) { this.Account = account; this.Account.Received += Account_Received; //подписка на событие this.Account.Sended += Account_Sended; //подписка на событие }