(原创)(C#随笔)IEnumerable< ICollection < IList区别

本文详细比较了.NET Framework中IEnumerable、ICollection<T>与IList<T>三个集合接口的功能特性及区别,展示了各自提供的方法与属性,强调了IList<T>相较于ICollection<T>在索引操作上的优势。

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

    public interface IEnumerable
    {
        IEnumerator GetEnumerator();
    }

再看ICollection<T>

    public interface ICollection<T> : IEnumerable<T>, IEnumerable
    {
        void Add(T item);
        void Clear();
        bool Contains(T item);
        void CopyTo(T[] array, int arrayIndex);
        bool Remove(T item);
        int Count {  get; }
        bool IsReadOnly { get; }
    }

再看IList<T>

    public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
    {
        int IndexOf(T item);
        void Insert(int index, T item);
        void RemoveAt(int index);
        T this[int index] {get;set; }
    }
可见,IList要比ICollection要多索引器的功能,另外还可以用索引器来进行修改,标识IList是可读写的链表,而ICollection是只读的链表;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值