/
ClsDelegateDemo2.cs
86 lines (85 loc) · 2.37 KB
/
ClsDelegateDemo2.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DelegatesandEvents
{
/// <summary>
/// Multicast Delegate outside of the class
/// </summary>
public class ClsDelegateDemo2
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// Addition Method
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public int Add(int a, int b)
{
int c = a + b;
log.Info("The Addition of two numbers:" + c);
return c;
}
/// <summary>
/// Subtraction Method
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public int Sub(int a, int b)
{
int c = a - b;
log.Info("The Subtraction of two numbers:" + c);
return c;
}
/// <summary>
/// Multiplication Method
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public int Mul(int a, int b)
{
int c = a * b;
log.Info("The Multiplication of two numbers:" + c);
return c;
}
/// <summary>
/// Division Method
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public int Div(int a,int b)
{
int c = a / b;
log.Info("The Division of two number:"+c);
return c;
}
}
/// <summary>
/// creating Delegate
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public delegate int mydelegate(int a, int b);
/// <summary>
/// Multicast Delegate
/// </summary>
public class MulticastDemo
{
/// <summary>
/// Main method instantiating and invoking delegate
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
ClsDelegateDemo2 obj = new ClsDelegateDemo2();
mydelegate obj1 = new mydelegate(obj.Add);
obj1 += obj.Sub;
obj1 += obj.Mul;
obj1 += obj.Div;
obj1(20, 6);
Console.ReadLine();
}
}
}