0

When creating an event, it is standard to send an EventArgs object as the second argument. However, often times the event may only need to send one piece of data, such as a string or int. As far as I know, you cannot really do anything with the base EventArgs class.

So is it really necessary to create an entire new class with one field just to send a simple string/int with an event?

Example

public delegate void JoinButtonEvent(object sender, string buttonId);

vs

public delegate void JoinButtonEvent(object sender, JoinButtonEventArgs e);

Where JoinButtonEventArgs is a class with field called buttonId.

jozenbasin
  • 2,142
  • 2
  • 14
  • 22

1 Answers1

1

No it's not necessary for your code to compile; but coding conventions wise its a good idea.

Sure you only care about one variable this time, but if you need another variable in the future you have to update all the old code to have an additional parameter instead of just adding another property to a central class when you need something new. (As events are not polymorphic, and can not be overridden like methods can be, to have different parameters for the same method name)

johng
  • 171
  • 9