Yes; delegates are compared by instance and MethodInfo; if they match then it will work. The problem occurs when you try to abandon the anonymous method; in this case, you must leave a link to the delegate to unsubscribe.
So:
This is normal:
control.SomeEvent += obj.SomeMethod;
control.SomeEvent -= obj.SomeMethod;
But this is much riskier:
control.SomeEvent += delegate {Trace.WriteLine("Foo");};
control.SomeEvent -= delegate {Trace.WriteLine("Foo");};
The correct process with anonymous methods:
EventHandler handler = delegate {Trace.WriteLine("Foo");};
control.SomeEvent += handler;
control.SomeEvent -= handler;
source
share