public string TestListEvent(bool clear = false) { string listItems = null; // Create the list ListWithChangedEvents <int> list = new ListWithChangedEvents <int>(); // Create the listener (instance) EventListener listener = new EventListener(list); // Now try to modify the list list.Add(numberToAdd); if (clear) { list.Clear(); } foreach (int item in list) { listItems += string.Format("Item: {0}\n", item.ToString()); } listener.Detach(); return(listItems); }
public void Detach() { // Detach the event and delete the list. List.Changed -= new ChangedEventHandler(ListChanged); List = null; }
public EventListener(ListWithChangedEvents <int> list) { this.List = list; // Add the method to be called at the changed event of the list. List.Changed += new ChangedEventHandler(ListChanged); }