How to Use Return Values from All Delegate Instances

If a delegate instance has an invocation list with multiple methods and you invoke the delegate using the standard functional notation, you’ll get back the return value in the invocation list.
If you want to consume the return value for each method in a delegate’s invocation list, you can use GetInvocationList to explicitly iterate through the invocation list.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ReturnIntDelegate del1 = Method1; // Returns 12
del1 += Method2;  // Returns 99
 
// Invoke all at once, get return value
// only from last
Console.WriteLine("Invoke normally");
int val = del1();
Console.WriteLine(val);
 
// Invoke one at a time
Console.WriteLine("Invoke one at a time");
foreach (ReturnIntDelegate del in del1.GetInvocationList())
{
    int ret = del.Invoke();
    Console.WriteLine(ret);
}
1022-001