将HybridDictionary条目复制到C#中的数组实例
要将HybridDictionary条目复制到数组实例,代码如下-
示例
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
HybridDictionary dict = new HybridDictionary();
dict.Add("1", "SUV");
dict.Add("2", "AUV");
dict.Add("3", "Utility Vehicle");
dict.Add("4", "MUV");
dict.Add("5", "Compact Car");
dict.Add("6", "Convertible");
Console.WriteLine("HybridDictionary Key and Value pairs...");
foreach(DictionaryEntry entry in dict){
Console.WriteLine("{0} and {1} ", entry.Key, entry.Value);
}
DictionaryEntry[] dictArr = new DictionaryEntry[10];
Console.WriteLine("\nCopied to Array Instance...");
dict.CopyTo(dictArr, 2);
for (int i = 0; i < dictArr.Length; i++)
Console.WriteLine("Key = "+dictArr[i].Key + ", Value = " + dictArr[i].Value);
}
}输出结果
这将产生以下输出-
HybridDictionary Key and Value pairs... 1 and SUV 2 and AUV 3 and Utility Vehicle 4 and MUV 5 and Compact Car 6 and Convertible Copied to Array Instance... Key = , Value = Key = , Value = Key = 1, Value = SUV Key = 2, Value = AUV Key = 3, Value = Utility Vehicle Key = 4, Value = MUV Key = 5, Value = Compact Car Key = 6, Value = Convertible Key = , Value = Key = , Value =
示例
现在让我们来看另一个示例-
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
HybridDictionary dict = new HybridDictionary(10);
dict.Add("1", "SUV");
dict.Add("2", "AUV");
dict.Add("3", "Utility Vehicle");
dict.Add("4", "MUV");
Console.WriteLine("HybridDictionary Key and Value pairs...");
foreach(DictionaryEntry entry in dict){
Console.WriteLine("{0} and {1} ", entry.Key, entry.Value);
}
DictionaryEntry[] dictArr = new DictionaryEntry[10];
Console.WriteLine("\nCopied to Array Instance...");
dict.CopyTo(dictArr, 0);
for (int i = 0; i < dictArr.Length; i++)
Console.WriteLine("Key = "+dictArr[i].Key + ", Value = " + dictArr[i].Value);
}
}输出结果
这将产生以下输出-
HybridDictionary Key and Value pairs... 1 and SUV 2 and AUV 3 and Utility Vehicle 4 and MUV Copied to Array Instance... Key = 1, Value = SUV Key = 2, Value = AUV Key = 3, Value = Utility Vehicle Key = 4, Value = MUV Key = , Value = Key = , Value = Key = , Value = Key = , Value = Key = , Value = Key = , Value =
热门推荐
1 祝福语简短的微信
10 生日祝福语 男性简短独特
11 朝鲜元旦祝福语大全简短
12 给孩子开学祝福语简短
13 圣诞祝福语简短给师姐
14 新年酒会祝福语简短创意
15 给表妹生日祝福语简短
16 周一祝福语简短精辟
17 升班祝福语简短10字
18 康复儿童六一祝福语简短