Solved

an array of events

Posted on 2004-10-12
1
446 Views
Last Modified: 2012-08-13
Hi,

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.

Thanks
0
Comment
Question by:bhanley9681
1 Comment
 
LVL 3

Accepted Solution

by:
a_goat earned 400 total points
ID: 12294694
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
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now