/// <summary> /// This method for using EventHandler /// </summary> protected virtual void OnNamesake(NamesakeEventArgs e) { EventHandler <NamesakeEventArgs> handler = Namesake; if (handler != null) { handler(this, e); } }
/// <summary> /// This method for find namesake in users list /// </summary> public void FindNamesake(string lastName) { NamesakeEventArgs args = new NamesakeEventArgs(); args.LastName = lastName; foreach (User u in users) { if (lastName == u.LastName) { OnNamesake(args); break; } } }
/// <summary> /// This method for using EventHandler /// </summary> public void NamesakeUsers(object sender, NamesakeEventArgs e) { Console.WriteLine("Namesake: "); List <User> namesakeUsers = new List <User>(users.Where(u => (u.LastName == e.LastName))); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Марина\Desktop\TAT_2018\task8\task8\file.txt")) { foreach (User u in namesakeUsers) { Console.WriteLine(u + "\n"); file.Write(u); } } }