When using events and the Invoke(), is there any harm in safeguarding it with the ‘?’
onHit?.Invoke();
Does it cost more performance ?
When using events and the Invoke(), is there any harm in safeguarding it with the ‘?’
onHit?.Invoke();
Does it cost more performance ?
I use it everywhere.
This is what is called null propogation, a form of syntactic sugar. The compiler actually expands this to
if(onHit!=null)
{
onHit();
}
What this means is that you don’t need to surround onHit?.Invoke(); with a null checking block.
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.