Reputation: 61
Can I shorten something like this
if (variable != null)
{
Function();
}
to something like this
variable? Function();
but that actually works ?
Upvotes: 1
Views: 85
Reputation: 925
No, you can't.
But if Function()
is a member of variable
you can use the null-conditional operator for the same effect:
variable?.Function();
Upvotes: 5