public void CountMessages(List <string> peopleList) { foreach (string person in peopleList) { // implement your logic to send name of people after apearing 3*n times if (!dic.ContainsKey(person)) { dic.Add(person, 1); } else { foreach (string name in dic.Keys) { if (person == name) { dic[name] += 1; if (dic[name] % 3 == 0) { PersonEventArgs p = new PersonEventArgs(); p.Name = person; OnContactNotify(p); // Notify subscribers } break; } } } } }
protected virtual void OnContactNotify(PersonEventArgs e) { EventHandler <PersonEventArgs> sender = ContactNotify; if (sender != null) { sender(this, e); } }
public static void Send(object source, PersonEventArgs e) { Console.WriteLine(e.Name); }