Dictionary of events?

Is there a way to create a dictionary of event objects How

This is what I have:

public delegate void MyDelegate();

This is the type of thing I would like:

private Dictionary<Object, event MyDelegate> listeners;

Is something like that possible I know I could use a List<MyDelegate> instead of an event but I would rather use the event for obvious reasons.

Thanks.


Answer this question

Dictionary of events?

  • Kai Huener

    Got it. Thanks. I didn't know the += operator was available for delegates.

  • Gaurav Srivastava

    try Dictionary<Object, MyDelegate>.

    Regards,

    Bernd


  • Darrell Snow

    No. It holds a list. A delegate is implicitly derived from MultiCast delegate. Therefore you should be able to call += new EventHandler(...) several times on every entry of your dictionary. Try it.

    Best regards,

    Bernd


  • leandro Oliveira

    If you're doing what I think you're trying and if they haven't fixed the problem in RTM then any events/delegates used with generics have extremely bad performance. There are several bugs listed on the feedback site (if it's still up and operational) about this.
  • Vinny Davi

    But then it is just holding a single delegate object per key. I want to hold a list of delegate (preferably as an event). Am I missing something

  • Guy_Dupre

    What do you think I am doing I am attempting to create a collection of event objects. I would like to use the generic Dictionary class to maintain the collection but I don't know how to add declare the collection since the compiler won't allow either Dictionary<Object, event MyDelegate> or Dictionary<Object, event>.

    That you state that there is a bug a performance issues seems to suggest that it is possible to do the above, however I cannot figure out the syntax that will allow it to compile.

  • Dictionary of events?