要创建具有指定初始大小的HybridDictionary,代码如下-
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
HybridDictionary dict = new HybridDictionary(5);
dict.Add("A", "AB");
dict.Add("B", "BC");
dict.Add("C", "DE");
dict.Add("D", "FG");
dict.Add("E", "HI");
Console.WriteLine("Key/Value pairs...");
foreach(DictionaryEntry d in dict)
Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value);
}
}输出结果
这将产生以下输出-
Key/Value pairs... Key = A, Value = AB Key = B, Value = BC Key = C, Value = DE Key = D, Value = FG Key = E, Value = HI
现在让我们来看另一个示例-
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
HybridDictionary dict = new HybridDictionary(10);
dict.Add("1", 100);
dict.Add("2", 200);
dict.Add("3", 300);
dict.Add("4", 400);
dict.Add("5", 500);
dict.Add("6", 600);
dict.Add("7", 700);
dict.Add("8", 800);
dict.Add("9", 900);
dict.Add("10", 1000);
Console.WriteLine("Key/Value pairs...");
foreach(DictionaryEntry d in dict)
Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value);
}
}输出结果
这将产生以下输出-
Key/Value pairs... Key = 10, Value = 1000 Key = 1, Value = 100 Key = 2, Value = 200 Key = 3, Value = 300 Key = 4, Value = 400 Key = 5, Value = 500 Key = 6, Value = 600 Key = 7, Value = 700 Key = 8, Value = 800 Key = 9, Value = 900