Reputation: 8415
I'm trying to create a dictionary to map an enum to a set of events with the same signature . I wrote :
public enum Events {Insert, Update, Delete};
// this part makes errors
Dictionary<Events,EventHandler<T>> EventsDic = new Dictionary<Events,EventHandler<T>>()
{
{ Events.Insert , this.ItemInserted}
};
what's wrong ?
Upvotes: 1
Views: 76
Reputation: 912
The problem is that T
has to be replaced with a type since you are declaring a variable. T
must be the type of the value
in the dictionary or, in your specific case, the type of the event arguments. Since you specifically say you are wanting to store events, T
should probably be the good old EventArgs
. Your code should look something like this:
Dictionary<Events,EventHandler<EventArgs>> EventsDic = new Dictionary<Events,EventHandler<EventArgs>>()
{
{ Events.Insert , this.ItemInserted}
};
Upvotes: 1