Hi,
I am trying events and delegates in my program on google search I came to see one code snippet. I couldn't get that in to which variable the output is going. Please help me..
public delegate void NumberArgumentHandle(object sender, NumberArgs args);
public event NumberArgumentHandle NumberSelected
{
add
{
Events.AddHandler(key, value);
}
remove
{
Events.RemoveHandler(key, value);
}
}
double x = double.MaxValue;
double.TryParse((sender as Button).Text, out x);
if (x != double.MaxValue)
{
NumberArgs args = new NumberArgs(Convert.ToDouble((sender as Button).Text));
RaiseEvent(args);
}
public class NumberArgs : EventArgs
{
double number = double.MaxValue;
public NumberArgs(double number)
{
this.number = number;
}
public double Number
{
get { return number; }
}
}
Loading
Master BillaPosted Sep 8, 2009, 10:23 AM
According your code, there is no ouput, it's just create event and make event registration with your object.
To learn event and delegate in c# from basic
http://www.akadia.com/services/dotnet_delegates_and_events.html
thank you
srinathPosted Sep 10, 2009, 2:17 AM
srinathPosted Sep 9, 2009, 11:06 AM
If I write RaiseEvent(args) in button keypress event of a usercontrol and call the output to a textbox in a windows application form. How should I call this..
regards,
s
srinathPosted Sep 9, 2009, 11:03 AM
Thank you for replying sir..
Sorry,I missed the code snippet for raising an event. this is
private void RaiseEvent(NumberArgs args)
{
if (Events[key] != null)
{
(Events[key] as NumberArgumentHandle)(this, args);
}
}
then where will be the output.