IEnumerable,ICollection,IList,List之間的區別

來源:互聯網
上載者:User

標籤:

首先我看看 IEnumerable:

// 摘要:    //     公開列舉程式,該列舉程式支援在指定類型的集合上進行簡單迭代。    //    // 型別參數:    //   T:    //     要枚舉的對象的類型。    [TypeDependency("System.SZArrayHelper")]    public interface IEnumerable<out T> : IEnumerable    {        // 摘要:        //     返回一個逐一查看集合的列舉程式。        //        // 返回結果:        //     可用於逐一查看集合的 System.Collections.Generic.IEnumerator<T>。        IEnumerator<T> GetEnumerator();    }

IEnumerable<T> 實現IEnumerable介面方法,那IEnumberable做什麼的,其實就提高可以逐一查看的集合。說白了就是一個迭代。

再來看看ICollection:

    // 摘要:    //     定義操作泛型集合的方法。    //    // 型別參數:    //   T:    //     集合中元素的類型。    [TypeDependency("System.SZArrayHelper")]    public interface ICollection<T> : IEnumerable<T>, IEnumerable    

原來ICollection<T> 同時繼承IEnumerable<T>和IEnumerable兩個介面,按我的理解就是,ICollection繼續它們2個介面而且擴充了方法,功能強多了。 
由原來的步槍變成半自動步槍

我們繼續看IList:

public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable

靠 IList 繼承它們三個介面,怪不得功能這麼多啊,那應該屬於全自動步槍了

最後來看看List:

public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable

這個時候大家仔細看看,它們都是介面,只有List 是類,不僅實現它們的介面,而且還擴充了太多的方法給我利用。哇靠,幾乎所有功能都能實現了,簡直是雷射步槍

按照功能排序:List<T> 《IList<T> 《ICollection<T>《IEnumerable<T>

按照效能排序:IEnumerable<T>《ICollection<T>《IList<T>《List<T>

IEnumerable,ICollection,IList,List之間的區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.