What does the ?
indicate in the following C# code?
var handler = CallBack;
handler?.Invoke();
I have read that you can use a ?
before a type to indicate that it is a nullable type. Is this doing the same thing?
What does the ?
indicate in the following C# code?
var handler = CallBack;
handler?.Invoke();
I have read that you can use a ?
before a type to indicate that it is a nullable type. Is this doing the same thing?
This is C#6 code using the null conditional operator
indicating that this code will not throw a NullReferenceException
exception if handler
is null:
Delegate handler = null;
handler?.Invoke();
which avoid you writing null checks that you would have to do in previous versions of the C# language:
Delegate handler = null;
if (handler != null)
{
handler.Invoke();
}