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

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

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

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

            // Добавление и удаление элементов списка.
            list.Add("item 1");
            list.Clear();
            listener.Detach();
        }
示例#6
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();
        }
示例#7
0
    // 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");//----- 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");//----- Adding item 2
        list.Add("item 2");
        //ListOnChanged(object sender, EventArgs eventArgs)
        //degate(object sender, EventArgs args)
        //(sender, args) =>

        list.Changed -= ListOnChanged;

        Console.WriteLine("----- Adding item 3");//----- Adding item 3
        list.Add("item 3");
        //degate(object sender, EventArgs args)
        //(sender, args) =>
    }
示例#8
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();
        }
示例#9
0
 public Form1()
 {
     InitializeComponent();
     list.Add("item 1");
     list.Add("item 2");
 }