For example:
delegate void SomeDelegate();
SomeDelegate a = new SomeDelegate( () => Console.WriteLine("A") );
SomeDelegate b = new SomeDelegate( () => Console.WriteLine("B") );
SomeDelegate c = a + b;
In the last line, what does a + b
translate to? I'm just curious how I would add them without using the +
operator.
http://msdn.microsoft.com/en-us/library/ms173172(v=VS.80).aspx - Search for addition:
Update
Both delegates derive from System.Delegate You can use the
combine()
methods to add two delegates together.It is done using
Delegate.Combine
static method.When using
+=
operator it is just the same actually.MulticastDelegate
class (the class behinddelegate
keyword) do have a list of invocations, but this list is immutable. Each time you combine delegates with the+=
operator, a newMulticastDelegate
instance get created combining the invocation list of the former two Delegate objects.