SortedDictionaryGeneric and SortedListGeneric

本文通过一个具体的示例展示了如何使用SortedDictionary类来存储并按键排序的键值对集合。该示例创建了一个SortedDictionary对象,并添加了一系列类型的名称作为值,以数字字符串作为键。最后遍历并打印了所有键值对及其哈希码。
SortedList<> and SortedDictionary<> Class Diagrams

Using SortedDictionary<TKey, TValue>
ContractedBlock.gifExpandedBlockStart.gifcode
 1None.gifusing System;
 2None.gifusing System.Collections.Generic;
 3None.gifclass Program
 4ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 5InBlock.gif
 6InBlock.gif    static void Main()
 7ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 8InBlock.gif        SortedDictionary<stringstring> dictionary = new
 9InBlock.gif             SortedDictionary<stringstring>();
10InBlock.gif        int index = 0;
11InBlock.gif        dictionary.Add(index++.ToString(), "object");
12InBlock.gif        dictionary.Add(index++.ToString(), "byte");
13InBlock.gif        dictionary.Add(index++.ToString(), "uint");
14InBlock.gif        dictionary.Add(index++.ToString(), "ulong");
15InBlock.gif        dictionary.Add(index++.ToString(), "float");
16InBlock.gif        dictionary.Add(index++.ToString(), "char");
17InBlock.gif        dictionary.Add(index++.ToString(), "bool");
18InBlock.gif        dictionary.Add(index++.ToString(), "ushort");
19InBlock.gif        dictionary.Add(index++.ToString(), "decimal");
20InBlock.gif        dictionary.Add(index++.ToString(), "int");
21InBlock.gif        dictionary.Add(index++.ToString(), "sbyte");
22InBlock.gif        dictionary.Add(index++.ToString(), "short");
23InBlock.gif        dictionary.Add(index++.ToString(), "long");
24InBlock.gif        dictionary.Add(index++.ToString(), "void");
25InBlock.gif        dictionary.Add(index++.ToString(), "double");
26InBlock.gif        dictionary.Add(index++.ToString(), "string");
27InBlock.gif
28InBlock.gif        Console.WriteLine("Key  Value   Hashcode");
29InBlock.gif        Console.WriteLine("---  ------  --------");
30InBlock.gif        foreach (KeyValuePair<stringstring> i in dictionary)
31ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
32InBlock.gif            Console.WriteLine("{0,-5}{1,-9}{2}",
33InBlock.gif                i.Key, i.Value, i.Key.GetHashCode());
34ExpandedSubBlockEnd.gif        }

35InBlock.gif
36InBlock.gif        Console.ReadKey();
37ExpandedSubBlockEnd.gif    }

38ExpandedBlockEnd.gif}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值