What is the open generic type of the array []?

3.4k views Asked by At

When I do int[], string[], T[] - this is a generic array. An array is just an object like everything else.

So what is the actual open generic type of []? I assume it is just some syntactic sugar over something like Array<> but I haven't been able to find anything of the sort.

Bonus points if you can somehow answer this before Jon Skeet.

4

There are 4 answers

2
Mark Sowul On BEST ANSWER
0
CodesInChaos On

Arrays are older that generics. Arrays are available since .net 1, and generics were only introduced in .net 2. So they are no syntax sugar on top of generics.

Instead they derive from Array and use a lot of runtime magic to work.

In addition arrays of a reference type support some variance patterns not supported by generics. If I recall correctly this was done for Java compatibility.

0
KeithS On

Far as I know, there wouldn't be an open generic type of Array; they existed before generics did in the .NET Framework. Arrays are just "weird"; the System.Array type exists mainly to provide O-O functionality to array objects. Only the runtime can derive from it.

HOWEVER, System.Array implements the generic IList<T>, which enforces the indexer. If you want an abstract that is strongly typed and will accept a strongly-typed array, use IList.

0
captain numerica On

It's not just syntactic sugar, it's an actual derivation of the System.Array class.