Let say, I want to pass some extra data when assigning an event handler. Consider the following code:
private void setup(string someData)
{
Object.assignHandler(evHandler);
}
public void evHandler(Object sender)
{
// need someData here!!!
}
How would I go about getting someData into my evHandler method?
Captured variables:
Or (C# 2.0 alternative):
My question that was similar was marked a duplicate so thought I'd add an answer here since it won't let me on my question.
You could create a custom object having additional properties based on Object:
If the data should not be changed anymore after initialization, you could also add a custom constructor, for example.
you can try doing this:
Well, the simplest method id to make
someData
a member variable like so:I'm not sure that's the best way to do it, but it really depends on the event type, the object, etc.