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
Next revision
Previous revision
notes:csharp:events [2017/01/10]
admin
notes:csharp:events [2019/09/26]
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>
  
  
-Also, these two code snippets are equivalent:+Also, the following two code snippets are equivalent:
 <code csharp> <code csharp>
 RatingChanged?.Invoke(this, args); // C# 6 (null conditional operator) RatingChanged?.Invoke(this, args); // C# 6 (null conditional operator)
notes/csharp/events.txt ยท Last modified: 2020/08/26 (external edit)