Skip to content

Commit 190605b

Browse files
CopilotBillWagner
andauthored
Fix nullable event warning in interface events documentation (#47684)
* Initial plan * Fix nullable event warning in interface events documentation Co-authored-by: BillWagner <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: BillWagner <[email protected]>
1 parent 8df888d commit 190605b

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

docs/csharp/programming-guide/events/how-to-implement-interface-events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ImplementInterfaceEvents
2929
}
3030
public class Shape : IDrawingObject
3131
{
32-
public event EventHandler ShapeChanged;
32+
public event EventHandler? ShapeChanged;
3333
void ChangeShape()
3434
{
3535
// Do something here before the event…

samples/snippets/csharp/VS_Snippets_VBCSharp/csProgGuideEvents/CS/Events.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,21 +686,18 @@ public class MyEventArgs : EventArgs
686686
}
687687
public class Shape : IDrawingObject
688688
{
689-
public event EventHandler ShapeChanged;
689+
public event EventHandler? ShapeChanged;
690690
void ChangeShape()
691691
{
692-
// Do something here before the event
692+
// Do something here before the event
693693

694694
OnShapeChanged(new MyEventArgs(/*arguments*/));
695695

696696
// or do something here after the event.
697697
}
698698
protected virtual void OnShapeChanged(MyEventArgs e)
699699
{
700-
if (ShapeChanged != null)
701-
{
702-
ShapeChanged(this, e);
703-
}
700+
ShapeChanged?.Invoke(this, e);
704701
}
705702
}
706703
}

0 commit comments

Comments
 (0)