IEnumeration与List之间的区别是什么?

17 浏览
0 Comments

IEnumeration与List之间的区别是什么?

这个问题已经有答案了:

IEnumerable vs List - What to Use? How do they work?

IList vs IEnumerable for Collections on Entities

我很困惑,请问有人可以帮我理解IEnumerationList的不同之处吗?

admin 更改状态以发布 2023年5月20日
0
0 Comments

你是指 IEnumerable。它是所有集合类型的基础接口,如数组或通用的 List

你可以例如创建一个 List

List ints = new List(){ 1,2,3 };

但由于它实现了 IEnumerable,你也可以这样声明它:

IEnumerable ints = new List(){ 1,2,3 };

这样做的好处是,你不能修改 ints,因为 Remove 来自 ICollection

0