array of events in C#?

前端 未结 4 1778
忘掉有多难
忘掉有多难 2020-12-20 18:04

basically:

public delegate void RecvCommandHandler (ChatApplication sender, byte[] content);
event RecvCommandHandler[] commands = new RecvCommandHandler[255         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 18:48

    There's really no concept of an array of events - it's like talking about an array of properties. Events are really just methods which let you subscribe and unsubscribe handlers. If you need to be able to do this by index, I suggest you just have a pair of methods. (AddCommandHandler(int, RecvCommandHandler) and RemoveCommandHandler(int, RecvCommandHandler)). That won't support the normal event handling syntactic sugar, of course, but I don't see that there's a lot of alternative.

提交回复
热议问题