diff --git a/docs/csharp/programming-guide/events/how-to-implement-interface-events.md b/docs/csharp/programming-guide/events/how-to-implement-interface-events.md index 0561e4e77ad91..81c49af87d8fd 100644 --- a/docs/csharp/programming-guide/events/how-to-implement-interface-events.md +++ b/docs/csharp/programming-guide/events/how-to-implement-interface-events.md @@ -29,7 +29,7 @@ namespace ImplementInterfaceEvents } public class Shape : IDrawingObject { - public event EventHandler ShapeChanged; + public event EventHandler? ShapeChanged; void ChangeShape() { // Do something here before the event… diff --git a/samples/snippets/csharp/VS_Snippets_VBCSharp/csProgGuideEvents/CS/Events.cs b/samples/snippets/csharp/VS_Snippets_VBCSharp/csProgGuideEvents/CS/Events.cs index 20f6f0797ce1d..6a959a4e65448 100644 --- a/samples/snippets/csharp/VS_Snippets_VBCSharp/csProgGuideEvents/CS/Events.cs +++ b/samples/snippets/csharp/VS_Snippets_VBCSharp/csProgGuideEvents/CS/Events.cs @@ -686,10 +686,10 @@ public class MyEventArgs : EventArgs } public class Shape : IDrawingObject { - public event EventHandler ShapeChanged; + public event EventHandler? ShapeChanged; void ChangeShape() { - // Do something here before the event� + // Do something here before the event… OnShapeChanged(new MyEventArgs(/*arguments*/)); @@ -697,10 +697,7 @@ void ChangeShape() } protected virtual void OnShapeChanged(MyEventArgs e) { - if (ShapeChanged != null) - { - ShapeChanged(this, e); - } + ShapeChanged?.Invoke(this, e); } } }