2
Answers

delegate and event for mathoperation

srinath

srinath

15y
2.5k
1

hi,
how to perform math operations like addition, subtraction, multiplication and division using delegates and events where all operations are treated separately.
I tried like this --  here I gave Math as eventargs in delegate declaration and I created a math class which refer eventargs. but in class I am not able to write the methods for individual arithmetic operations. I want to raise an  event using Math class object.
public
delegate void MathOperationHandler(object sender,Math m)
public
event MathOperationHandler op
{
add
{
Events.AddHandler(key,
value);
}
remove
{
Events.RemoveHandler(key,
value);
}
}

public
class Math : EventArgs
{
double n1 = double.MaxValue;
double n2 = double.MaxValue;
public Math(double num1, double num2)
{
this.n1 = num1;
this.n2 = num2;
}
public double num1
{
get { return num1; }

}
public double num2
{
get { return num2; }
}
}
private void RaiseEvent(Math m)
{
if (Events[key] != null)
{
(Events[key]
as MathOperationHandler)(this, m);
}
}

 

 Am I doing correctly . please, help me....
Answers (2)