-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
109 lines (78 loc) · 2.86 KB
/
Program.cs
File metadata and controls
109 lines (78 loc) · 2.86 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
public delegate void MathDelegate(int No1, int No2);
public class Rectangle
{
public delegate void RectangleDelege(double Width, double Height);
public void GetArea(double Width, double Height)
{
Console.WriteLine($"Area is {Width * Height}");
}
public void GetPerimeter(double Width, double Height) {
Console.WriteLine($"Perimeter is {2 * (Width + Height)}");
}
// Declaring static Methods
//Static Method
public static void Add(int x, int y)
{
Console.WriteLine($"Addition of {x} and {y} is : {x + y}");
}
//Static Method
public static void Sub(int x, int y)
{
Console.WriteLine($"Subtraction of {x} and {y} is : {x - y}");
}
//Non-Static Method
public void Mul(int x, int y)
{
Console.WriteLine($"Multiplication of {x} and {y} is : {x * y}");
}
//Non-Static Method
public void Div(int x, int y)
{
Console.WriteLine($"Division of {x} and {y} is : {x / y}");
}
static void Main(string[] args)
{
// First method to Multicast Delegate
//Rectangle rect = new Rectangle();
//RectangleDelege rectDelegate = new RectangleDelege(rect.GetArea);
//rectDelegate += rect.GetPerimeter;
//Delegate[] InvocationList = rectDelegate.GetInvocationList();
//Console.WriteLine("InvocationList");
//foreach(var item in InvocationList)
//{
// Console.WriteLine($" {item}");
//}
//Console.WriteLine();
//Console.WriteLine("Invoking Multicast Delegate:");
//rectDelegate(23.45, 67.89);
//// rectDelegate.Invoke(13.45, 76.89);
//Console.WriteLine();
//Console.WriteLine("Invoking Multicast Delegate After Removing one Pipeline:");
////Removing a method from delegate object
//rectDelegate -= rect.GetPerimeter;
//rectDelegate.Invoke(13.45, 76.89);
//Console.ReadKey();
//Second Method to Multicast Delegates
Rectangle rect2 = new Rectangle();
MathDelegate del1 = new MathDelegate(Add);
MathDelegate del2 = new MathDelegate(Rectangle.Sub);
MathDelegate del3 = new MathDelegate(rect2.Mul);
MathDelegate del4 = new MathDelegate(rect2.Div);
// del5 will be the Multicast
MathDelegate del5 = del1 + del2 + del3 + del4;
Delegate[] invocationList = del5.GetInvocationList();
Console.WriteLine("InvocationList:");
foreach(var item in invocationList)
{
Console.WriteLine($" {item}");
}
Console.WriteLine();
Console.WriteLine("Invoking Multicast Delegate::");
del5.Invoke(20, 5);
Console.WriteLine();
Console.WriteLine("Invoking Multicast Delegate After Removing one Delegate:");
del5 -= del2;
del5(22, 7);
Console.ReadKey();
}
}