Given that implementation, yes, they will always be called in that order.
If the event actually uses some weird and wonderful way of handling subscriptions, it could do different things - but "normal" implementations will do the right thing.
To be clear, subscribing to an event handler just means invoking the appropriate "add" part of an event. If the event handles this by doing something like:
myHandler += value;
that gets translated into
myHandler = Delegate.Combine(myHandler, value);
and Delegate.Combine guarantees the ordering. However, if you had an event like this:
private LinkedList<EventHandler> eventHandlers = new LinkedList<EventHandler>;
public event EventHandler Foo
{
add
{
eventHandlers.AddFirst(value);
}
remove
{
// do stuff here too
}
}
and then fired the event by doing something like:
foreach (EventHandler handler in eventHandlers)
{
handler(this, EventArgs.Empty);
}
then the handlers would be called in the reverse order.
Summary: For all sane events, you can rely on the ordering. In theory, events can do what they like, but I've never seen an event which doesn't maintain the appropriate ordering.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…