My answer is more of a comment for Thomas Levesque, but I can't comment yet, so here goes nothing. I find this area of C# a little ugly, since there's a possibility to introduce race conditions - i.e. different threads may race and you may enter the if
statement with CheckedChanged != null
if (CheckedChanged == null)
{
CheckedChanged += (s, e) =>
{
// code;
}
}
You should either lock this code, but in many cases you will find yourself writing code like this
//Invoke SomeEvent if there are any handlers attached to it.
if(SomeEvent != null) SomeEvent();
But SomeEvent may be nulled in the process, so it would be safer to write something like this
SomeEVentHandler handler = SomeEvent;
if (handler != null) handler();
...just to be extra safe.