首页 > 其他 > 详细

C#中的Collection 3

时间:2014-04-23 17:41:25      阅读:606      评论:0      收藏:0      [点我收藏+]

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

 

bubuko.com,布布扣 + bubuko.com,布布扣

Can do:

IList<T> - access by index

IEnumerable<T> - foreach

ICoolection<T> - Collection initialzers

Array - All array can do

Collection<T>

是IList<T>的另一种Implementation

bubuko.com,布布扣

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

方法:

bubuko.com,布布扣

如上图,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的事情

bubuko.com,布布扣

 

 

 

 

C#中的Collection 3,布布扣,bubuko.com

C#中的Collection 3

原文:http://www.cnblogs.com/shawnzxx/p/3682450.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!