C#中SortedList 和 SortedDictionary集合类型
来源:互联网 发布:苹果下载软件 编辑:程序博客网 时间:2024/05/17 22:57
a: System.Collections.Generic的SortedList
b.: System.Collections.Generic的SortedDictionary
1.a与b的作用:
能够存储数据并自动按照key进行排序。
2.定义与使用:
SortedDictionary<key,value>
SortedList<key,value>
其中key与排序有关,value为值且可以为值或引用类型。
// SortedDictionary
SortedDictionary<int, string> sDictionary = new SortedDictionary<int, string>();
sDictionary.Add(3, "cc");
sDictionary.Add(4, "dd");
sDictionary.Add(1, "aa");
sDictionary.Add(2, "bb"); // 此处可以发现sDictionary已经自动按key进行了排序
// 得到SortedDictionary的所有key的集合
SortedDictionary<int, string>.KeyCollection keys = sDictionary.Keys;
// 得到SortedDictionary的所有value的集合
SortedDictionary<int, string>.ValueCollection values = sDictionary.Values;
//SortedList
SortedList<int, string> sList = new SortedList<int, string>();
sList.Add(3, "cc");
sList.Add(4, "dd");
sList.Add(1, "aa");
sList.Add(2, "bb"); // 此处可以发现sList已经自动按key进行了排序
// 得到SortedList的所有key的集合
IList<int> keysList = sList.Keys;
// 得到SortedList的所有value的集合
IList<string> valuesList = sList.Values;
3.二者区别
SortedList 泛型类是具有 O(log n) 检索的二进制搜索树,其中 n 是字典中元素的数目。就这一点而言,它与 SortedDictionary 泛型类相似。这两个类具有相似的对象模型,并且都具有 O(log n) 的检索运算复杂度。这两个类的区别在于内存的使用以及插入和移除元素的速度:
SortedList 使用的内存比 SortedDictionary 少。
SortedDictionary 可对未排序的数据执行更快的插入和移除操作,它的运算复杂度为 O(log n),而 SortedList 的运算复杂度为 O(n)。
如果使用排序数据一次性填充列表,则 SortedList 比 SortedDictionary 快。
4.与List相比的优势是能够自动排序
List的排序请看另一篇文章。
- C#中SortedList 和 SortedDictionary集合类型
- C# Dictionary, SortedDictionary, SortedList
- C#集合类详解,Hashtable 和 SortedList 类,Dictionary 和 SortedLi,Array ,ArrayList ,List ,Stack,SortedDictionary ,ListDictionary ,StringDic
- C#学习笔记集合类型之Hashtable、Dictionary和SortedList(2)
- Dictionary, SortedDictionary, SortedList 比较
- Dictionary, SortedDictionary, SortedList 比较
- SortedList,SortedDictionary比较
- C#集合之SortedList
- .NET源码中的SortedDictionary<TKey, TValue>和SortedList<TKey, TValue>
- C#中SortedDictionary 的使用
- C# Dictionary和SortedDictionary简介
- C#常用的集合类型(ArrayList类、Stack类、Queue类、Hashtable类、SortedList类)
- C#常用的集合类型(ArrayList类、Stack类、Queue类、Hashtable类、SortedList类) 收藏
- C#常用的集合类型(ArrayList类、Stack类、Queue类、Hashtable类、SortedList类)
- C#常用的集合类型(ArrayList类、Stack类、Queue类、Hashtable类、SortedList类)
- C# List和SortedList简介
- Hashtable、Dictionary、SortedDictionary、SortedList的比较应用
- C# 集合类(五):SortedList
- C# 中 for和foreach 性能比较,提高编程性能
- 读书时间 2011/12/24 iPhone/iPad
- 数据库通配符使用
- Android手机上邮箱的设置通用方法
- 35个惊人的 CSS3 动画演示
- C#中SortedList 和 SortedDictionary集合类型
- windows的磁盘镜像的稳定性
- Web app设计浅谈
- 关于项目开发的感想!
- struts2 实现原理解析
- 既是案例也是广告,可能还是别的
- rsync , rsync + ssh, rsync + lsyncd 多种同步方案与比较
- Google 以图搜图 - 相似图片搜索原理 - Java实现
- 用Telnet模拟HTTP请求的两篇文章