What is the purpose of "?" in (someDelegateName)?.Invoke();?
This is the null conditional operator.
drawMethodsDelegate?.Invoke ( e.Graphics );
Provided that drawMethodsDelegate
is not null calls the Invoke
method. It is an operator that being introduced in the 6th version of C# and you can see it as a syntactic sugar, which helps you to write less code for handling null checks.
Last but not least, the above check is also thread-safe !
For further info please have a look here
This is a null condition operator that came with C# 6.0
https://msdn.microsoft.com/en-us/library/dn986595.aspx
it means IF drawMethodsDelegate is not null Invoke the method else do nothing.