zoukankan      html  css  js  c++  java
  • C#中的Collection 3

    IList<T> 和 ICollection<T>

    最重要的一些类型

    List<T>: Encapsulates[T], like array, but also provide with adding/removing elemnts

    ReadOnlyCollection<T>: Read-only wrapper for lists

    Collection<T>: Allow lists to be customized

    ObservableCollection<T>: List with changes notifications

     

     List<T>

    What: List<T>是IList<T>的一种implementation

     

     + 

    Can do:

    IList<T> - access by index

    IEnumerable<T> - foreach

    ICoolection<T> - Collection initialzers

    Array - All array can do

    Collection<T>

    是IList<T>的另一种Implementation

    比如:我们建立一个list must only accept non-blank, non-null strings. 用List<T>就不成

    方法:

    如上图,Collection<T> encapsulate 了List<T>,其含有ICollection interface为其带来的Add()方法,和IList<T>的insert和this[index],但是这些方法都不可以重写。

    幸运的是这些方法都会call底层的一个virtual方法,insertItem和setItem,我们可以重写这两个方法,从而 customize 我们的collection。

    ObervableCollection<T>

    主要是利用里面的CollectionChanged event, 其实他也是从Collection<T> customize出来的特殊类型,microsoft自己也经常用collection<T>做一些custmize的事情

     

     

     

  • 相关阅读:
    Spring_配置 Bean(2)
    Spring_HelloWorld
    搭建 Spring 开发环境
    MongoDB快速入门(十三)- 聚合count、distinct和group
    缓存技术,封装好的缓存类
    HTTP协议详解
    C# 缓存技术
    Web Service 的工作原理
    webview长按保存图片
    android Webview 实现js调用java代码实现Activity跳转
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3682450.html
Copyright © 2011-2022 走看看