Exemplo n.º 1
0
 //Listing 82
 public static void CreateAndRaise()
 {
     Pub p = new Pub();
     p.OnChange += () => Console.WriteLine("Event Raised to method 1");
     p.OnChange += () => Console.WriteLine("Event Raised to method 2");
     p.Raise();
 }
Exemplo n.º 2
0
 public static void CreateAndRaiseOne()
 {
     Pub p = new Pub();
     //the below code is incorrect, an event cannot be directly assigned to operator
     //p.OnChangeOne = () => Console.WriteLine("Event Raised to method 1");
     p.OnChangeOne += () => Console.WriteLine("Event Raised to method 2");
     p.RaiseOne();
 }
Exemplo n.º 3
0
 //Listing 87
 public static void CreateAndRaiseFour()
 {
     Pub p = new Pub();
     p.OnChangeFour += (sender, e) => Console.WriteLine("Subscriber 1 called");
     p.OnChangeFour += (sender, e) => { throw new Exception(); }; /*Console.WriteLine("Subscriber 2 called");*/
     p.OnChangeFour += (sender, e) => Console.WriteLine("Subscriber 3 called");
     try { p.RaiseFour();}
     catch(AggregateException ex) { Console.WriteLine(ex.InnerExceptions.Count); }
 }
Exemplo n.º 4
0
 //Listing 84
 public static void CreateAndRaiseTwo()
 {
     Pub p = new Pub();
     p.OnChangeTwo += (sender, e) => Console.WriteLine("Event raised: {0}", e.Value);
     p.RaiseTwo();
 }