public EventListener(ListWithChangedEvent list) { List = list; List.Changed += new ChangeEventHandler(OnListChanged); List.fizz += new FizzBuzzEventHandler(OnFizzFound); List.fizz += new FizzBuzzEventHandler(Print); List.buzz += new FizzBuzzEventHandler(OnBuzzFound); List.buzz += new FizzBuzzEventHandler(Print); List.fizzbuzz += new FizzBuzzEventHandler(OnFizzBuzzFound); List.fizzbuzz += new FizzBuzzEventHandler(Print); }
static void Main(string[] args) { // create a new list ListWithChangedEvent list = new ListWithChangedEvent(); // creeat a class that listens for when the list is changed EventListener listener = new EventListener(list); list.Print(); list.FizzBuzz(); list.Print(); listener.Detatch(); Console.ReadKey(); }
static void Main(string[] args) { // create a new list ListWithChangedEvent list = new ListWithChangedEvent(); // create a class that litens for when the list is changed EventListener listener = new EventListener(list); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Add(5); list.Add(15); list.Add(30); Console.WriteLine(); list.PrintList(); list.FizzBuzz(); list.Clear(); listener.Detatch(); Console.ReadKey(); }
static void Main(string[] args) { int[] num = { 1, 2, 3, 4, 5, 6, 15, 30 }; // Create a new list ListWithChangedEvent list = new ListWithChangedEvent(); // Create a class that listens for when the list is changed EventListener listener = new EventListener(list); for (int i = 0; i < num.Length; i++) { list.Add(num[i]); } Console.WriteLine(); list.PrintList(); list.FizzBuzz(); list.PrintList(); list.Clear(); listener.Detatch(); Console.ReadKey(); }
public void Detatch() { List.Changed -= new ChangeEventHandler(OnListChanged); List = null; }