The return value from a delegate instance is passed back to the caller. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | private delegate int ReturnIntDelegate(); static int Method1() { return 12; } static void Main( string [] args) { ReturnIntDelegate del1 = Method1; // Invoke int val = del1(); Console.WriteLine(val); } |
Recall, however, that a delegate instance can refer to more than one method. When a caller invokes a delegate whose invocation list contains more than one method, the value returned to the caller is the return value of the last delegate instance in the invocation list. Return values of other methods in the invocation list are lost.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | static int Method1() { return 12; } static int Method2() { return 99; } static void Main( string [] args) { ReturnIntDelegate del1 = Method1; del1 += Method2; // Invoke int val = del1(); Console.WriteLine(val); } |