C# Events and Lambdas, alternative to null check?
- by Eugarps
Does anybody see any drawbacks? It should be noted that you can't remove anonymous methods from an event delegate list, I'm aware of that (actually that was the conceptual motivation for this).
The goal here is an alternative to:
if (onFoo != null) onFoo.Invoke(this, null);
And the code:
public delegate void FooDelegate(object sender, EventArgs e);
public class EventTest
{
public EventTest()
{
onFoo += (p,q) => { };
}
public FireFoo()
{
onFoo.Invoke(this, null);
}
public event FooDelegate onFoo;
}