"Remove the check for null. Instead use NullableObject?.Invoke()"
In C#, from version 6, the ?.
expression can be used to simplify the code.
Delegate handler = null;
...
if (handler != null)
{
handler.Invoke();
}
should be 🡻
Delegate handler = null;
...
handler?.Invoke();
public void OnXYZ(SomeEventArgs e)
{
var evt = XYZ;
if (evt != null)
evt(sender, e);
}
should be 🡻
public void OnXYZ(SomeEventArgs e) => XYZ?.Invoke(sender, e);