开发者

T[] stands for array, why not IEnumerable<T>? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜