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 ?
The problem is that
Thas to be replaced with a type since you are declaring a variable.Tmust be the type of thevaluein the dictionary or, in your specific case, the type of the event arguments. Since you specifically say you are wanting to store events,Tshould probably be the good oldEventArgs. Your code should look something like this: