T[] stands for array, why not IEnumerable<T>? [closed]
Why does T[]开发者_JAVA百科
stand for array and not IEnumerable<T>
in C#?
I know that generics were introduced in .NET 2.0. If it was designed from scratch, does it make any sense to map []
to array? Actively using LINQ extension methods, I'd prefer to write simple T[]
instead of bulky IEnumerable<T>
or explicit .ToArray()
.
I'm wondering just for academic reasons.
T[]
is the standard syntax for arrays for statically-typed C-like languages. If .NET 1.0 had generics, arrays might have used an Array<T>
type.
At any rate, if T[]
was used for IEnumerable<T>
it could only be used in declarations and you wouldn't be able to create one using new T[] { ... }
. As far as interfaces go, it would make more sense to map it to IList<T>
since the square brackets imply indexing.
精彩评论