User Tools

Site Tools


notes:csharp:events

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
notes:csharp:events [2017/03/29]
leszek
notes:csharp:events [2019/09/26] (current)
leszek
Line 47: Line 47:
         public event EventHandler<​RatingChangedArgs>​ RatingChanged;​         public event EventHandler<​RatingChangedArgs>​ RatingChanged;​
  
-        // [4] Wrap event invocations inside a protected virtual method+        // [3] Wrap event invocations inside a protected virtual method
         // to allow derived classes to override the event invocation behavior.         // to allow derived classes to override the event invocation behavior.
         protected virtual void OnRatingChanged(RatingChangedArgs args)         protected virtual void OnRatingChanged(RatingChangedArgs args)
Line 69: Line 69:
                     return;                     return;
  
-                // [5] Inform subscribers when video rating has changed.+                // [4] Inform subscribers when video rating has changed.
                 OnRatingChanged(new RatingChangedArgs(rating,​ value));                 OnRatingChanged(new RatingChangedArgs(rating,​ value));
                 rating = value;                 rating = value;
Line 84: Line 84:
             this.id = id;             this.id = id;
  
-            // [6] Subscribe to the event.+            // [5] Subscribe to the event.
             clip.RatingChanged += Subscriber_RatingChanged;​             clip.RatingChanged += Subscriber_RatingChanged;​
         }         }
  
-        // [7] Define what actions to take when the event is raised.+        // [6] Define what actions to take when the event is raised.
         private void Subscriber_RatingChanged(object sender, RatingChangedArgs args)         private void Subscriber_RatingChanged(object sender, RatingChangedArgs args)
         {         {
Line 109: Line 109:
             Subscriber s2 = new Subscriber("​s2",​ clip);             Subscriber s2 = new Subscriber("​s2",​ clip);
  
-            // [8] Raise the RatingChanged event.+            // [7] Raise the RatingChanged event.
             clip.Rating = 4.9f; // change the rating             clip.Rating = 4.9f; // change the rating
         }         }
Line 131: Line 131:
 In the above code the following two lines are equivalent: In the above code the following two lines are equivalent:
 <code csharp> <code csharp>
-// [6] Subscribe to the event.+// [5] Subscribe to the event.
 clip.RatingChanged += Subscriber_RatingChanged;​ // C# 2.0 clip.RatingChanged += Subscriber_RatingChanged;​ // C# 2.0
 </​code>​ </​code>​
  
 <code csharp> <code csharp>
-// [6] Subscribe to the event.+// [5] Subscribe to the event.
 clip.RatingChanged += new EventHandler<​RatingChangedArgs>​(Subscriber_RatingChanged);​ // C# 1.1 clip.RatingChanged += new EventHandler<​RatingChangedArgs>​(Subscriber_RatingChanged);​ // C# 1.1
 </​code>​ </​code>​
notes/csharp/events.1490837537.txt.gz ยท Last modified: 2017/03/29 by leszek