kuskmen kuskmen - 1 year ago 78
C# Question

Why GetInvocationList of System.Delegate class returns array?

I am trying to learn how delegates work so I watched over the hierarchy and I found that invocation list of a System.Delegate is actually an array. If all the methods are invoked with the FIFO principle why not store the Delegates in Stack?

In other words why signature of the method


doesn't look
public virtual Stack<Delegate> GetInvocationList()

rather than
public virtual Delegate[] GetInvocationList()
or I am missing something?

Answer Source
  1. Delegates are a language feature that was in .NET since its inception.
  2. Data structure to store invocation list is just a design decision, but it couldn't be Stack<T> because this collection was introduced in .NET 2.0 (earlier versions had no generic collections or generics at all, they were introduced in .NET 2.0/CLR 2.0).

Based on both points, I suspect that it was never changed from Array to another data structure because of it would mean that .NET 1.x code would be broken so they decided to maintain backwards compatibility.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download