lenelex.com
Home
Quizzes
Games
Register
Log in
Question 1 of 14
What is the output of the following program?
class Program { delegate void D(int x, int y); static void A(int x, int y) => Console.Write(x + y); static void B(int x, int y) => Console.Write(x - y); static void Main() { D a = A; D b = B; D all = a + b; all(4, 2); } }
A. 42
B. 62
C. 8
D. 6
Delegate multicasting
A delegate can call more than one method when invoked. This is referred to as multicasting. To add an extra method to delegate's list of methods (the invocation list), use the addition or addition assignment operators ('+' or '+='). To remove a method from the invocation list, use the decrement or decrement assignment operator ('-' or '-=').
Links:
Delegates
delegate