public delegate void MyDelegate(int a, int b);
public class Test
{
public event MyDelegate MyEvent;
public void RaiseEvent(int a, int b)
{
MyEvent(a, b);
Console.WriteLine("Event Raised");
}
public void Add(int x, int y)
{
Console.WriteLine("Add Method {0}", x + y);
}
public void Subtract(int x, int y)
{
Console.WriteLine("Subtract Method {0}", x - y);
}
}
private void Main1()
{
Test obj = new Test();
obj.MyEvent += new MyDelegate(obj.Add);
obj.MyEvent += new MyDelegate(obj.Subtract);
obj.RaiseEvent(20, 10);
Console.ReadKey();
}
***********************************************************************************
**
internal class Program
{
static void Main(string[] args)
{
Test obj = new Test();
obj.Name = "Rupa";
obj.Age = 39;
Console.WriteLine($"Employee Name:{obj.Name}, Age:{obj.Age}");
Console.WriteLine("******************************************");
Calculator calc = new Calculator();
calc.Number1 = 45;
calc.Number2 = 30;
calc.Add();
Console.WriteLine($"Result of addition : {calc.Result}");
Console.WriteLine("************************************************");
calc.Substract();
Console.WriteLine($"Result of substraction : {calc.Result}");
Console.WriteLine("*************************************************");
Console.ReadKey();
}
class Test
{
string name;
public string Name { get { return name; } set { name = value; } }
int age;
public int Age { get { return age; } set { age = value; } }
}
class Calculator
{
int number1,number2,result;
public int Number1 { set { number1 = value; } }
public int Number2 { set { number2 = value; } }
public int Result { get { return result; } }
public void Add()
{
result = number1 + number2;
}
public void Substract()
{
result = number1 - number2;
}
public int GetResult()
{
return result;
}
}
}
***********************************************************************************