- fckeditor在ie9中不支持$=document.getElementById解决办法
- 网站备案注销方法 关于网站备案问题的解答
- excel中$是什么意思
- Image.ImageUrl 屬性
- c#中访问修饰符public,private,protected,internal,protected internal的区别
- 主机/vps/服务器
- ->是什么意思?
- StringBuilder在.Net中的用法说明
- asp.net中使用#include语法将文件添加到页面
- ACCESS表中 文本的字段长度设定
邮箱:
手机:15383239821
C#中SortedList 和 SortedDictionary集合类型 .
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的排序请看另一篇文章。
-
2023-08-28php中global的用法是什么?
-
2011-04-12C#常用代码
-
2011-04-15mysql防注入的sql语句写法
-
2019-11-18判断asp.net上传图片时图片RGB或CMYK模式的方法
-
2012-07-02谈域名包含关键词的作用
-
2019-11-22JS中的arguments参数
