static void Main(string[] args) { var user = new User { FullName = "Джеф Безос" }; var account = new BankAccount { User = user, }; //account.RegisterSender(new AccountMessageDelegate(Console.WriteLine)); account.RegisterSender(Console.WriteLine); account.RegisterSender(new ConsoleSender().SendMessage); account.Add(200); account.Withdraw(100); account.Withdraw(200); Console.ReadKey(); }
static void Main(string[] args) { var account = new BankAccount { OwnerName = "Вася Петров", }; //account.RegisterDelegate(new AcccountSenderDelegate(new ConsoleMessageSender().SendMessage)); //account.RegisterDelegate(new AccountSenderDelegate(Console.WriteLine)); //account.RegisterDelegate(new AccountSenderDelegate(new ConsoleMessageSender().SendMessage)); account.MessageSendEvent += Console.WriteLine; //Дефолтные делегаты Action action = Console.WriteLine; // void //Func<int, int, int> sum = Sum; //возвращаемый_тип; //delegate ( параметры) { тело; return возвращаемый_тип; } account.MessageSendEvent += delegate(string message) { Console.WriteLine(message); }; // лямбда выражение - (параметры) => { тело; return значение;} account.MessageSendEvent += x => Console.WriteLine(x); account.Add(200); account.Withdraw(100); account.Withdraw(300); var list = new List <string> { "Астана", "Алматы", "Буенос-Айрес" }; var longResult = new List <string>(); foreach (var city in list) { if (city.ToLower().Contains("с")) { longResult.Add(city); } } var result = list.Where(city => city.ToLower().Contains("с")).ToList(); SmtpClient Smtp = new SmtpClient("smtp.yandex.ru", 25); Smtp.Credentials = new NetworkCredential("*****@*****.**", "qpRJ8b^XTbpp"); MailMessage Message = new MailMessage(); Message.From = new MailAddress("*****@*****.**"); Message.To.Add(new MailAddress("*****@*****.**")); Message.Subject = "Message From Bank"; Message.Body = "Здравствуйте, уважаемый " + account.OwnerName + "\n Мы бы хотели вас оповестить о том что " + Message; try { Smtp.Send(Message); } catch (SmtpException) { MessageBox.Show("Ошибка!"); } Console.Read(); }