Nika Varamashvili
Nika Varamashvili

Reputation: 21

How can Delegate call many methods?

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

Answers (1)

Marc Gravell
Marc Gravell

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

Related Questions