ICollection<T> IEnumerable<T>
ICollection<T>
和 IEnumerable<T>
都是 .NET Framework 中的泛型接口,用于表示集合类型。
IEnumerable<T>
接口表示一组可以枚举的元素,该接口只包含一个方法 GetEnumerator()
,该方法返回一个枚举器,用于遍历集合中的元素。该接口是只读的,不能对集合进行修改。
ICollection<T>
接口扩展了 IEnumerable<T>
接口,表示一组可以枚举的元素,并且还可以对集合进行修改。该接口包含许多方法,如 Add()
, Remove()
, Contains()
, Clear()
等,用于对集合进行添加、删除、查找和清空操作。
因此,ICollection<T>
接口比 IEnumerable<T>
接口更加丰富,可以进行更多的操作。但是,由于 IEnumerable<T>
接口只提供了枚举器方法,因此它比 ICollection<T>
接口更加通用,可以用于表示任何可以枚举的集合类型。
c# list<> 方法
C# 中 List
Add(T item):在列表的末尾添加一个元素。
AddRange(IEnumerable
collection):在列表的末尾添加一个集合中的所有元素。 Insert(int index, T item):在列表的指定位置插入一个元素。
InsertRange(int index, IEnumerable
collection):在列表的指定位置插入一个集合中的所有元素。 Remove(T item):从列表中删除指定的元素。
RemoveAt(int index):从列表中删除指定位置的元素。
RemoveRange(int index, int count):从列表中删除指定位置开始的指定数量的元素。
Clear():从列表中删除所有元素。
Contains(T item):确定列表是否包含指定的元素。
IndexOf(T item):返回指定元素在列表中的索引。
LastIndexOf(T item):返回指定元素在列表中最后出现的索引。
Count:获取列表中的元素数量。
Sort():对列表中的元素进行排序。
Reverse():将列表中的元素按相反的顺序排列。
ToArray():将列表转换为数组。
这些是 List
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)