惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CERT Recently Published Vulnerability Notes
U
Unit 42
T
The Blog of Author Tim Ferriss
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Securelist
L
Lohrmann on Cybersecurity
Blog — PlanetScale
Blog — PlanetScale
Recorded Future
Recorded Future
D
DataBreaches.Net
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
I
Intezer
P
Palo Alto Networks Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
I
InfoQ
宝玉的分享
宝玉的分享
Security Latest
Security Latest
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threatpost
Cisco Talos Blog
Cisco Talos Blog
P
Proofpoint News Feed
博客园 - 司徒正美
H
Hacker News: Front Page
Y
Y Combinator Blog
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
NISL@THU
NISL@THU
月光博客
月光博客
有赞技术团队
有赞技术团队
Cloudbric
Cloudbric
酷 壳 – CoolShell
酷 壳 – CoolShell
G
Google Developers Blog
A
Arctic Wolf
博客园 - 【当耐特】
W
WeLiveSecurity
V
Visual Studio Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
V
V2EX
C
Cyber Attacks, Cyber Crime and Cyber Security
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Stack Overflow Blog
Stack Overflow Blog

博客园 - yfcomeon

浅谈C#托管程序中的资源释放问题 (转载) 静态构造函数的执行时机 详解javascript类继承机制的原理 通用高效分页存储过程 Attributes in C# 组装机 散列基本概念知识点 C#的6种常用集合类大比拼 C#中的集合类 C#里的委托和事件实现 C#方法修饰符 C#类和接口及值类型和引用类型的区别 vc调试器 变量的域 SQL数据库空间不足怎么办 分页 B树算法 转:sql server系统表详细说明 转:sql server系统表详细说明
C#中的集合类
yfcomeon · 2007-10-30 · via 博客园 - yfcomeon

1.System.Colloctions中表示集合的行为的接口有:
1)ICollection
定义所有集合的大小、枚举数和同步方法。派生于IEnumerable
它定义了集合类最基本的行为,所有的集合类都实现了这个接口(基接口)
但是它的行为太过基本:主要就是一个Count属性,单独实现它没有太大意义

2)IEnumerable
公开枚举数,该枚举数支持在集合上进行简单迭代
它只有一个方法 GetEnumerator(),该方法可以返回一个IEnumerator接口,通过它可以遍历集合
基本上所有的集合类都实现了这个接口

3)IList
IList实现是可排序且可按照索引访问其成员的值的集合,它本身实现了ICollection和IEnumerable接口
是所有列表的抽象基类。IList 实现有三种类别:只读、固定大小、可变大小。

4)IDictionary
IDictionary实现是键/值对的集合,它本身实现了ICollection和IEnumerable接口
是键/值对的集合的基接口。IDictionary 实现有三种类别:只读、固定大小、可变大小。
IDictionary可称为字典、映射或散列表,它根据键(任意类型)来访问值

------------------------------

2.System.Collections中可以直接使用的集合类有:
1)ArrayList
实现了接口:IList、ICollection、IEnumerable
只要集合未被修改,ArrayList 就可安全地同时支持多个读取器
随着向 ArrayList 中添加元素,容量通过重新分配按需自动增加(2倍增加)
如果需要建立一个对象数组,但不能预先知道数组的大小,就可以使用ArrayList
ArrayList把所有元素都当作object对象引用,因而在访问ArrayList的元素时要进行类型转换
优点:动态改变大小、灵活方便的插入和删除元素、可排序
缺点:插入时性能不如数组、不是强类型的

2)BitArray
实现了接口:ICollection、IEnumerable
管理位值的压缩数组。

3)Hashtable
实现了接口:IDictionary、ICollection、IEnumerable
可以向Hashtable中自由添加和删除元素,有些像ArrayList,但没有那么大的性能开销

4)SortedList
实现了接口:IDictionary、ICollection、IEnumerable
SortedLIst兼顾了ArrayList和Hashtable的优点,可按键值来排序

5)Queue
实现了接口:ICollection、IEnumerable
Queque是队列,先进先出的访问各个元素
可以调用Queque对象的GetEnumerator()方法,得到IEnumerator对象,来遍历队列中的各个元素

6)Stack
实现了接口:ICollection、IEnumerable
Stack是堆栈,后进先出的访问各个元素
可以调用Stack对象的GetEnumerator()方法,得到IEnumerator对象,来遍历堆栈中的各个元素

例如,简单实现遍历arraylist的个项

protected ArrayList subordinates;
IEnumerator enumSub 
= subordinates.GetEnumerator() ;
            
while (enumSub.MoveNext())  {
                esub 
= (Employee)enumSub.Current;
                sum 
+= esub.getSalaries();
            }