- .Net验证控件1
- 网站推广实战:100条不容错过的经验
- slideDown() 方法
- SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed
- 较短的网站域名有以下几点好处
- utf-8、utf8mb4和utf8mb3有什么区别
- 如何在百度知道留下你的链接.
- 多个关键词优化秘诀
- 详解SQL Server数据库索引
- 在C# webapi中的 [FromBody] [FromForm]的区别
邮箱:
手机:15383239821
C#中SortedDictionary 的使用
TKey
字典中的键的类型。
TValue
字典中的值的类型。
SortedDictionary 泛型类是检索运算复杂度为 O(log n) 的二叉搜索树,其中 n 是字典中的元素数。就这一点而言,它与 SortedList 泛型类相似。这两个类具有相似的对象模型,并且都具有 O(log n) 的检索运算复杂度。这两个类的区别在于内存的使用以及插入和移除元素的速度:
-
SortedList 使用的内存比 SortedDictionary 少。
-
SortedDictionary 可对未排序的数据执行更快的插入和移除操作:它的时间复杂度为 O(log n),而 SortedList 为 O(n)。
-
如果使用排序数据一次性填充列表,则 SortedList 比 SortedDictionary 快。
每个键/值对都可以作为 KeyValuePair 结构进行检索,或作为 DictionaryEntry 通过非泛型 IDictionary 接口进行检索。
只要键用作 SortedDictionary 中的键,它们就必须是不可变的。SortedDictionary 中的每个键必须是唯一的。键不能为 空引用(在 Visual Basic 中为 Nothing),但是如果值类型 TValue 为引用类型,该值则可以为空。
SortedDictionary 需要比较器实现来执行键比较。可以使用一个接受 comparer 参数的构造函数来指定 IComparer 泛型接口的实现;如果不指定实现,则使用默认的泛型比较器 Comparer.Default。如果类型 TKey 实现 System.IComparable 泛型接口,则默认比较器使用该实现。
C# 语言的 foreach 语句,需要集合中每个元素的类型。由于 SortedDictionary 的每个元素都是一个键/值对,因此元素类型既不是键的类型,也不是值的类型。而是 KeyValuePair 类型。下面的代码演示 C# 语法
using System;
using System.Collections.Generic;
public class Example
{
}
× This code example produces the following output:
An element with Key = "txt" already exists.
For key = "rtf", value = wordpad.exe.
For key = "rtf", value = winword.exe.
Key = "tif" is not found.
Key = "tif" is not found.
Value added for key = "ht": hypertrm.exe
Key = txt, Value = notepad.exe
Key = bmp, Value = paint.exe
Key = dib, Value = paint.exe
Key = rtf, Value = winword.exe
Key = doc, Value = winword.exe
Key = ht, Value = hypertrm.exe
Value = notepad.exe
Value = paint.exe
Value = paint.exe
Value = winword.exe
Value = winword.exe
Value = hypertrm.exe
Key = txt
Key = bmp
Key = dib
Key = rtf
Key = doc
Key = ht
Remove("doc")
Key "doc" is not found.
×/
-
2010-12-21SQL选择不重复记录
-
2012-07-02提高关键词排名和网站收录
-
2024-10-11优化property=og标签,让你的网站在搜索引擎面前更优雅
-
2010-11-16导致网站降权的六种错误分析
-
2024-07-21vue组合api中ref
-
2013-08-20手机网页的制作方法一_新建手机网页
