Question

For classes which derive from EventArgs, how mutable should their data be?

I know there might be a case of "it depends", but since the object is potentially getting passed around a lot, it makes me think that it should be as immutable as possible:

public class MyEventArgs : EventArgs
{
    public int Value { get; private set; }

    public MyEventArgs(int value)
    {
        Value = value;
    }
}
Was it helpful?

Solution

Sometimes, members of your custom EventArgs class are used to return information back to the event caller (to the object which owns / triggers the event).

In that cases, the member should be editable.

One prominent example is http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs.handled(v=vs.110).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top