Reputation: 21
Delegate is a reference to a method: 1 address to 1 memory cell, i.e. of our method. So when I link more methods to one delegate, how can this one address call many methods?
Upvotes: 2
Views: 102
Reputation: 1062520
Delegate is a reference to a method: 1 address to 1 memory cell
Not necessarily it isn't. Delegates can be combined, via +
, which is shorthand for Delegate.Combine
. Invoking the composite delegate will involve each target in turn.
So:
SomeDelegate x = obj.Whatever;
SomeDelegate y = arg => other.SomeMethod(arg, capturedLocal);
SomeDelegate z = x + y;
z(42);
Upvotes: 1