(+N) Consulting Inc.

Consulting | Software Solutions | Training

Generics - delegate and custom event args

When you want to create custom events, often you need to pass an event argument, and as often you need only to pass in one parameter - your object.   So what you used to do is: public event MyCustomEventHandler MyCustomEvent; public delegate void MyCustomEventHandler(MyCustomEventArg evt); public class MyObject { public string foo; public int count; public DateTime when; public MyObject() { foo = "hello world"; count = 42; when = DateTime.Now; } public override string ToString() { return string.Format("{0}\t{1}\t{2}",foo,count,when); } } public class MyCustomEventArg : EventArgs { private MyObject _value; public MyObject Data { get { return _value; } set { _value = value; } } ... [More]