数组和List各有偏重,怎么可以厚此而薄彼。
数组是集合的一种。官方的说法是:
1.集合类定义为 System.Collections 或 System.Collections.Generic 命名空间的一部分。
2.大多数集合类都派生自 ICollection、IComparer、IEnumerable、IList、IDictionary 和 IDictionaryEnumerator 接口以及它们的等效泛型接口。
更一般的说法是:
“在 C# 中,集合类并非必须严格从 IEnumerable 和 IEnumerator 继承才能与 foreach 兼容;只要类有所需的 GetEnumerator、MoveNext、Reset 和 Current 成员,便可以与 foreach 一起使用。省略接口的好处为,使您可以将 Current 的返回类型定义得比 object 更明确,从而提供了类型安全。”
温馨提示:答案为网友推荐,仅供参考