参考MSDN:下面的代码示例演示如何使用 Dictionary<(Of <(TKey, TValue>)>)(IEqualityComparer<(Of <(TKey>)>)) 构造函数,利用来自另一个字典的已排序内容初始化 Dictionary<(Of <(TKey, TValue>)>)。该代码示例创建一个 SortedDictionary<(Of <(TKey, TValue>)>) 并在其中随机填充数据,然后将 SortedDictionary<(Of <(TKey, TValue>)>) 传递给 Dictionary<(Of <(TKey, TValue>)>)(IEqualityComparer<(Of <(TKey>)>)) 构造函数,创建一个经过排序的 Dictionary<(Of <(TKey, TValue>)>)。如果需要生成一个某些时候是静态的排序字典,这将十分有用;将数据从 SortedDictionary<(Of <(TKey, TValue>)>) 复制到 Dictionary<(Of <(TKey, TValue>)>) 可提高检索速度。
using System;
using System.Collections.Generic;public class Example
{
public static void Main()
{
// Create a new sorted dictionary of strings, with string
// keys.
SortedDictionary<string, string> openWith =
new SortedDictionary<string, string>(); // Add some elements to the dictionary.
openWith.Add("txt", "notepad.exe");
openWith.Add("bmp", "paint.exe");
openWith.Add("dib", "paint.exe");
openWith.Add("rtf", "wordpad.exe"); // Create a Dictionary of strings with string keys, and
// initialize it with the contents of the sorted dictionary.
Dictionary<string, string> copy =
new Dictionary<string, string>(openWith); // List the contents of the copy.
Console.WriteLine();
foreach( KeyValuePair<string, string> kvp in copy )
{
Console.WriteLine("Key = {0}, Value = {1}",
kvp.Key, kvp.Value);
}
}
}/* This code example produces the following output:Key = bmp, Value = paint.exe
Key = dib, Value = paint.exe
Key = rtf, Value = wordpad.exe
Key = txt, Value = notepad.exe
*/
using System;
using System.Collections.Generic;public class Example
{
public static void Main()
{
// Create a new sorted dictionary of strings, with string
// keys.
SortedDictionary<string, string> openWith =
new SortedDictionary<string, string>(); // Add some elements to the dictionary.
openWith.Add("txt", "notepad.exe");
openWith.Add("bmp", "paint.exe");
openWith.Add("dib", "paint.exe");
openWith.Add("rtf", "wordpad.exe"); // Create a Dictionary of strings with string keys, and
// initialize it with the contents of the sorted dictionary.
Dictionary<string, string> copy =
new Dictionary<string, string>(openWith); // List the contents of the copy.
Console.WriteLine();
foreach( KeyValuePair<string, string> kvp in copy )
{
Console.WriteLine("Key = {0}, Value = {1}",
kvp.Key, kvp.Value);
}
}
}/* This code example produces the following output:Key = bmp, Value = paint.exe
Key = dib, Value = paint.exe
Key = rtf, Value = wordpad.exe
Key = txt, Value = notepad.exe
*/
解决方案 »
- 根据窗口的句柄怎么遍历子句柄?
- Socket的原理:监听socket和传输socket是怎么实现的
- 窗体之间的调用怎么写?急。。。。。
- 请问如何得到继承SoapHttpClientProtocol类中xml的内容?
- C#调用C++开发的Webservice
- visual studio tab control
- C# Remoting 服务端客户端问题(要求改进)
- 我想开发一个软件,可以画很多框框和箭头,然后在框框里填图象和文字,然后可以保存起来,需要什么准备知识?界面要用哪些控件好?(详)
- WeifenLuo Document窗口问题。
- 大家给出出招吧,国际化问题
- 关于一个排列模式的问题
- 如何遍历html中的链接?
SortedList泛型可以使用index来获取。Another difference between the SortedDictionary and SortedList classes is that SortedList supports efficient indexed retrieval of keys and values through the collections returned by the Keys and Values properties. It is not necessary to regenerate the lists when the properties are accessed, because the lists are just wrappers for the internal arrays of keys and values. The following code shows the use of the Values property for indexed retrieval of values from a sorted list of strings:
发现csdn这个论坛有点垃圾(用了一些自以为是的技术但是不适用)。。-_-!!!
wxg:你的答复并没解决lz问题。
但起码查了下,有点参考价值,
对看贴的朋友也会有点帮助的不是吗?PS:与CSDN无关吧
应该不能吧,由于LZ要比较的是UserInfo类中的的某个属性,不遍历能比较出来??!!
最简单的Array也有啊!!Array.Short();//