// Test the ListWithChangedEvent class.
    public static void Main()
    {
        // Create a new list.
        ListWithChangedEvent list = new ListWithChangedEvent();

        // Add and remove items from the list.
        Console.WriteLine("----- Adding item 1");
        list.Add("item 1");
        list.Clear();

        // Attach method as a listener
        // list.Changed += new ChangedEventHandler(ListOnChanged);
        list.Changed += ListOnChanged;

        // Attach delegate as a listener
        list.Changed += delegate(object sender, EventArgs args)
        {
            Console.WriteLine("degate(object sender, EventArgs args)");
        };

        // Attach anonymous type as a listener
        list.Changed += (sender, args) => Console.WriteLine("(sender, args) =>");

        Console.WriteLine("----- Adding item 2");
        list.Add("item 2");

        list.Changed -= ListOnChanged;

        Console.WriteLine("----- Adding item 3");
        list.Add("item 3");
    }
Example #2
0
 public void Detach()
 {
     // (3.2) Remove a delegate from a (possibly composite) field.
     // Detach the event and delete the list
     List.Changed -= new ChangedEventHandler(ListChanged);
     List          = null;
 }
Example #3
0
            public EventListener(ListWithChangedEvent list)
            {
                this.list = list;

                // Add "ListChanged" to the Changed event on list:
                this.list.Changed += new System.EventHandler(ListChanged);
            }
    // Test the ListWithChangedEvent class.
    public static void Main()
    {
        // Create a new list.
        ListWithChangedEvent list = new ListWithChangedEvent();

        // Add and remove items from the list.
        Console.WriteLine("----- Adding item 1");
        list.Add("item 1");
        list.Clear();

        // Attach method as a listener
        // list.Changed += new ChangedEventHandler(ListOnChanged);
        list.Changed += ListOnChanged;

        // Attach delegate as a listener
        list.Changed += delegate(object sender, EventArgs args)
            {
                Console.WriteLine("degate(object sender, EventArgs args)");
            };

        // Attach anonymous type as a listener
        list.Changed += (sender, args) => Console.WriteLine("(sender, args) =>");

        Console.WriteLine("----- Adding item 2");
        list.Add("item 2");

        list.Changed -= ListOnChanged;

        Console.WriteLine("----- Adding item 3");
        list.Add("item 3");
    }
Example #5
0
        public static void Main()
        {
            ListWithChangedEvent list = new ListWithChangedEvent();

            EventListener listener = new EventListener(list);

            list.Add("item 1");
            list.Clear();
            listener.Detach();
        }
Example #6
0
        public static void Main(string[] a)
        {
            ListWithChangedEvent list = new ListWithChangedEvent();

            EventListner ev = new EventListner(list);

            list.Add("item1");
            list.Clear();
            ev.Detach();
        }
Example #7
0
        public static void Demo()
        {
            ListWithChangedEvent list     = new ListWithChangedEvent();
            EventListener        listener = new EventListener(list);

            list.Add("item 1");
            list[0] = "item_correct";
            list.Clear();
            listener.Detach();
        }
Example #8
0
        public static void Main()
        {
            ListWithChangedEvent list     = new ListWithChangedEvent();
            EventListener        listener = new EventListener(list);

            list.Add("item 1"); //list gets changed
            list.Add("item 2"); //list gets changed
            list.Clear();       //list gets changed
            listener.Detach();
            Console.ReadKey();
        }
Example #9
0
    // Test the ListWithChangedEvent class.
    public static void Main () {
        // Create a new list.
        ListWithChangedEvent list = new ListWithChangedEvent();

        // 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();
    }
Example #10
0
        // 测试 ListWithChangedEvent 类。
        public static void Main()
        {
            // 创建新列表。
            ListWithChangedEvent list = new ListWithChangedEvent();

            // 创建一个类,用于侦听列表的更改事件。
            EventListener listener = new EventListener(list);

            // 在列表中添加和移除项。
            list.Add("item 1");
            list.Clear();
            listener.Detach();
        }
Example #11
0
        // Тестирование класса ListWithChangedEvent.
        public static void Main()
        {
            // Создание нового списка.
            ListWithChangedEvent list = new ListWithChangedEvent();

            // Создание класса, ожидающего событий изменения списка.
            EventListener listener = new EventListener(list);

            // Добавление и удаление элементов списка.
            list.Add("item 1");
            list.Clear();
            listener.Detach();
        }
Example #12
0
            // Test the ListWithChangedEvent class:
            static void Main()
            {
                // Create a new list:
                ListWithChangedEvent list = new ListWithChangedEvent();

                // 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();
            }
Example #13
0
            public EventListener(ListWithChangedEvent list)
            {
                List = list;

                // (3) Hooking up to an event   From outside the class that
                // declared it, an event looks like a field, but access to that
                // field is very restricted. The only things that can be done
                // are:
                // (3.1) Compose a new delegate onto that field.
                // Add "ListChanged" to the Changed event on "List".


                List.Changed += new ChangedEventHandler(ListChanged);
            }
Example #14
0
        private static void Main(string[] args)
        {
            ListWithChangedEvent<int> list = new ListWithChangedEvent<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
             EventLisener<int> sub1 = new EventLisener<int>("sub1", list);
             EventLisener<int> sub2 = new EventLisener<int>("sub2", list);

             list.Add(10);
             list[9] = 100;
             list.Clear();

             // Keep the console window open
             Console.WriteLine("Press Enter to close this window.");
             Console.ReadLine();
        }
Example #15
0
        // Test the ListWithChangedEvent class.
        public static void Main()
        {
            // Create a new list.
            ListWithChangedEvent list = new ListWithChangedEvent();

            // 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");

            Console.WriteLine("{0}", list[0]);
            list.Clear();
            listener.Detach();
        }
Example #16
0
 public void Detach()
 {
     List.Changed -= new ChangedEventHandler(ListChanged);
     List          = null;
 }
Example #17
0
 public void Detach()
 {
     // Detach the event and delete the list:
     list.Changed -= new System.EventHandler(ListChanged);
     list          = null;
 }
Example #18
0
 public void Detach()
 {
     // Отсоединение события и удаление списка
     List.Changed -= new ChangedEventHandler(ListChanged);
     List          = null;
 }
Example #19
0
 public void Detach()
 {
     // 分离事件并删除列表:
     List.Changed -= new EventHandler(ListChanged);
     List          = null;
 }
Example #20
0
 public void Detach () {
     // Detach the event and delete the list
     List.Changed -= new ChangedEventHandler(ListChanged);
     List = null;
 }
Example #21
0
 public EventListener (ListWithChangedEvent list) {
     List = list;
     // Add "ListChanged" to the Changed event on "List".
     List.Changed += new ChangedEventHandler(ListChanged);
 }
Example #22
0
 public void Detach()
 {
     // Detach the event and delete the list
     List.Changed -= new ChangedEventHandler(ListChanged);
     List          = null;
 }
Example #23
0
 public EventListener(ListWithChangedEvent list)
 {
     List = list;
     // Add "ListChanged" to the Changed event on "List".
     List.Changed += new ChangedEventHandler(ListChanged);
 }
Example #24
0
 public EventListener(ListWithChangedEvent list)
 {
     List = list;
     // 将“ListChanged”添加到“List”中的 Changed 事件。
     List.Changed += new ChangedEventHandler(ListChanged);
 }
Example #25
0
 public EventListener(ListWithChangedEvent list)
 {
     List = list;
     // добавления "ListChanged" к событию Changed для "List".
     List.Changed += new ChangedEventHandler(ListChanged);
 }
Example #26
0
 public EventListener(ListWithChangedEvent list)
 {
     List          = list;
     List.Changed += new ChangedEventHandler(ListChanged);
 }