In the console application, several objects are created that are subscribed to the event. We need to find out for which objects the event handler worked and display their name. For this, I decided to create a list and a method that adds signed events to this list. But it is not the names that are displayed, but the "assembly_name" .Person.

List<Person> allPersons = new List<Person>(); public void AddPersonToOffice(Person person) { if (allPersons.Contains(person)) return; allPersons.Add(person); this.EmpoyerComeIn += person.IsComing; foreach (var all in allPersons) { Console.WriteLine(all); } 
  • 2
    Console.WriteLine(all.Name); - Igor
  • The question is, if I call this method in Main, office. AddPersonToOffice () ;, what do I need to pass to the method so that it displays the names of all the objects? - cruim
  • The question is - am I a telepath or am I not a telepath? A little telepathic. There you must pass an object of type Person , which is not contained in the list of allPersons . - Igor
  • Then it turns out that the name of this object will be displayed, right? And if there are several such objects? Suppose Person firstPerson = new Person ("Volume"); office.AddPersonToOffice (firstPerson); - cruim
  • no, the names of all the objects contained in the allPersons list are allPersons . Try it. - Igor

0