示例#1
0
        static void Main(string[] args)
        {
            // Create a new list.
            CustomEventsListWithChangedEvent list = new CustomEventsListWithChangedEvent();

            // Create a class that listens to the list's change event.
            EventListener listener = new EventListener(list);

            // Add and remove items from the list.
            list.Add("item 1");
            list.Clear();
            listener.Detach();
            Console.Read();
        }
示例#2
0
        static void Main(string[] args)
        {
            // Create a new list.
            CustomEventsListWithChangedEvent list = new CustomEventsListWithChangedEvent();

            // Create a class that listens to the list's change event.
            EventListener listener = new EventListener(list);

            // Add and remove items from the list.
            list.Add("item 1");
            list.Clear();
            listener.Detach();
            Console.Read();
        }
示例#3
0
 public void Detach()
 {
     // Detach the event and delete the list
     List.Changed -= new ChangedEventHandler(ListChanged);
     List = null;
 }
示例#4
0
 public EventListener(CustomEventsListWithChangedEvent list)
 {
     List = list;
     // Add "ListChanged" to the Changed event on "List".
     List.Changed += new ChangedEventHandler(ListChanged);
 }
示例#5
0
 public void Detach()
 {
     // Detach the event and delete the list
     List.Changed -= new ChangedEventHandler(ListChanged);
     List          = null;
 }
示例#6
0
 public EventListener(CustomEventsListWithChangedEvent list)
 {
     List = list;
     // Add "ListChanged" to the Changed event on "List".
     List.Changed += new ChangedEventHandler(ListChanged);
 }