关于List《T》,还是是懂非懂

本文详细介绍了List<T>泛型类的使用方法及其继承的多个接口,包括IList<T>、ICollection<T>和IEnumerable<T>等,并通过实例展示了如何创建不同类型的集合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于List<T>,还是是懂非懂:

List<T>泛型类,表示可通过索引访问的对象的强类型列表。提供用于对列表进行搜索、排序和操作的方法。
public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable

IList<T> 泛型接口,表示可按照索引单独访问的一组对象。
ICollection<T> 泛型接口,定义操作泛型集合的方法。
IEnumerable<T> 泛型接口,公开枚举数,该枚举数支持在指定类型的集合上进行简单迭代。
IList 接口,表示可按照索引单独访问的对象的非泛型集合。
ICollection 接口,定义所有非泛型集合的大小、枚举数和同步方法。
IEnumerable 接口,公开枚举数,该枚举数支持在非泛型集合上进行简单迭代。

所以,以下都可以:
IList<Company> companyy1 = new List<Company>();
ICollection<Company> companyy2 = new List<Company>();
IEnumerable<Company> companyy3 = new List<Company>();

IList companyy4 = new List<Company>();
ICollection companyy5 = new List<Company>();
IEnumerable companyy6 = new List<Company>();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值