-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiCastDelegate.cs
More file actions
39 lines (35 loc) · 956 Bytes
/
MultiCastDelegate.cs
File metadata and controls
39 lines (35 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
/*
* The delegates can point to multiple method. A delegate that point multiple method is
* called multi-cast delegate. The "+" operator adds a function to the delegate object
* and "-" remove an existing function from a delegate object.
*
*/
namespace ConsoleApp81
{
internal class Test
{
public delegate void Print(int value);
public static void Main()
{
var print =new Print(PrintNumber);
print += PrintHexaDecimal;
print += PrintMoney;
print(1000);
print -= PrintHexaDecimal;
print(2000);
}
private static void PrintMoney(int money)
{
Console.WriteLine("Money: {0:C}", money);
}
private static void PrintHexaDecimal(int value)
{
Console.WriteLine("Hexadecimal: {0:X}", value);
}
private static void PrintNumber(int value)
{
Console.WriteLine("Number: {0,-12:N0}", value);
}
}
}