// 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"); }
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; }
public EventListener(ListWithChangedEvent list) { this.list = list; // Add "ListChanged" to the Changed event on list: this.list.Changed += new System.EventHandler(ListChanged); }
public static void Main() { ListWithChangedEvent list = new ListWithChangedEvent(); EventListener listener = new EventListener(list); list.Add("item 1"); list.Clear(); listener.Detach(); }
public static void Main(string[] a) { ListWithChangedEvent list = new ListWithChangedEvent(); EventListner ev = new EventListner(list); list.Add("item1"); list.Clear(); ev.Detach(); }
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(); }
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(); }
// 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(); }
// 测试 ListWithChangedEvent 类。 public static void Main() { // 创建新列表。 ListWithChangedEvent list = new ListWithChangedEvent(); // 创建一个类,用于侦听列表的更改事件。 EventListener listener = new EventListener(list); // 在列表中添加和移除项。 list.Add("item 1"); list.Clear(); listener.Detach(); }
// Тестирование класса ListWithChangedEvent. public static void Main() { // Создание нового списка. ListWithChangedEvent list = new ListWithChangedEvent(); // Создание класса, ожидающего событий изменения списка. EventListener listener = new EventListener(list); // Добавление и удаление элементов списка. list.Add("item 1"); list.Clear(); listener.Detach(); }
// 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(); }
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); }
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(); }
// 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(); }
public void Detach() { List.Changed -= new ChangedEventHandler(ListChanged); List = null; }
public void Detach() { // Detach the event and delete the list: list.Changed -= new System.EventHandler(ListChanged); list = null; }
public void Detach() { // Отсоединение события и удаление списка List.Changed -= new ChangedEventHandler(ListChanged); List = null; }
public void Detach() { // 分离事件并删除列表: List.Changed -= new EventHandler(ListChanged); List = null; }
public void Detach () { // Detach the event and delete the list List.Changed -= new ChangedEventHandler(ListChanged); List = null; }
public EventListener (ListWithChangedEvent list) { List = list; // Add "ListChanged" to the Changed event on "List". List.Changed += new ChangedEventHandler(ListChanged); }
public void Detach() { // Detach the event and delete the list List.Changed -= new ChangedEventHandler(ListChanged); List = null; }
public EventListener(ListWithChangedEvent list) { List = list; // Add "ListChanged" to the Changed event on "List". List.Changed += new ChangedEventHandler(ListChanged); }
public EventListener(ListWithChangedEvent list) { List = list; // 将“ListChanged”添加到“List”中的 Changed 事件。 List.Changed += new ChangedEventHandler(ListChanged); }
public EventListener(ListWithChangedEvent list) { List = list; // добавления "ListChanged" к событию Changed для "List". List.Changed += new ChangedEventHandler(ListChanged); }
public EventListener(ListWithChangedEvent list) { List = list; List.Changed += new ChangedEventHandler(ListChanged); }