• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

an array of events


I would like to create an array of events for a project that I'm working on - is this possible?

I'm not talking about having a single event call many handlers - I know how to do that.

1 Solution
There's no way to directly create an array of events.  You can do it indirectly though:

public class MyEventManager
public event EventHandler MyEvent;

public class MyFoo
public MyEventManager[] OnEvent = new MyEventManager[10];
public MyFoo()
for (int I = 0; I < OnEvent.Length; I++)
OnEvent[I] = new MyEventManager();

Then you can add an event like:

MyFoo Junk = new MyFoo();
Junk.OnEvent[2].MyEvent += [blah blah blah]

You might even be able to do it in a sneakier way, so you don't have to use the "MyEvent" when assigning the event handler
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now