首先我看看 IEnumerable:

// 摘要: // 公開(kāi)枚舉器,該枚舉器支持在指定類(lèi)型的集合上進(jìn)行簡(jiǎn)單迭代。 // // 類(lèi)型參數(shù): // T: // 要枚舉的對(duì)象的類(lèi)型。 [TypeDependency("System.SZArrayHelper")] public interface IEnumerable<out T> : IEnumerable { // 摘要: // 返回一個(gè)循環(huán)訪問(wèn)集合的枚舉器。 // // 返回結(jié)果: // 可用于循環(huán)訪問(wèn)集合的 System.Collections.Generic.IEnumerator<T>。 IEnumerator<T> GetEnumerator(); }
IEnumerable<T> 實(shí)現(xiàn)IEnumerable接口方法,那IEnumberable做什么的,其實(shí)就提高可以循環(huán)訪問(wèn)的集合。說(shuō)白了就是一個(gè)迭代。
再來(lái)看看ICollection:

// 摘要: // 定義操作泛型集合的方法。 // // 類(lèi)型參數(shù): // T: // 集合中元素的類(lèi)型。 [TypeDependency("System.SZArrayHelper")] public interface ICollection<T> : IEnumerable<T>, IEnumerable 
原來(lái)ICollection<T> 同時(shí)繼承IEnumerable<T>和IEnumerable兩個(gè)接口,按我的理解就是,ICollection繼續(xù)它們2個(gè)接口而且擴(kuò)展了方法,功能強(qiáng)多了。由原來(lái)的步槍變成半自動(dòng)步槍
我們繼續(xù)看IList:
publicinterfaceIList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
靠 IList 繼承它們?nèi)齻€(gè)接口,怪不得功能這么多啊,那應(yīng)該屬于全自動(dòng)步槍了
最后來(lái)看看List:
public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
這個(gè)時(shí)候大家仔細(xì)看看,它們都是接口,只有List 是類(lèi),不僅實(shí)現(xiàn)它們的接口,而且還擴(kuò)展了太多的方法給我利用。哇靠,幾乎所有功能都能實(shí)現(xiàn)了,簡(jiǎn)直是激光步槍
按照功能排序:List<T> 《IList<T> 《ICollection<T>《IEnumerable<T>
按照性能排序:IEnumerable<T>《ICollection<T>《IList<T>《List<T>
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注