将StringDictionary复制到C#中指定索引处的数组
要将StringDictionary复制到指定索引处的Array,代码如下-
示例
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
StringDictionary strDict = new StringDictionary();
strDict.Add("1", "SUV");
strDict.Add("2", "AUV");
strDict.Add("3", "Electric Car");
strDict.Add("4", "Utility Vehicle");
strDict.Add("5", "Hatchback");
strDict.Add("6", "Compact car");
strDict.Add("7", "MUV");
strDict.Add("8", "Crossover");
strDict.Add("9", "Covertible");
strDict.Add("10", "Quadricycle");
DictionaryEntry[] arr = { new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry()};
strDict.CopyTo(arr, 0);
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine(arr[i].Key + " " + arr[i].Value);
}
}
}输出结果
这将产生以下输出-
10 Quadricycle 1 SUV 2 AUV 3 Electric Car 4 Utility Vehicle 5 Hatchback 6 Compact car 7 MUV 8 Crossover 9 Covertible
示例
现在让我们来看另一个示例-
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
StringDictionary strDict = new StringDictionary();
strDict.Add("1", "SUV");
strDict.Add("2", "AUV");
strDict.Add("3", "Electric Car");
strDict.Add("4", "Utility Vehicle");
strDict.Add("5", "Hatchback");
strDict.Add("6", "Compact car");
DictionaryEntry[] arr = { new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry(),
new DictionaryEntry()};
strDict.CopyTo(arr, 2);
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine(arr[i].Key + " " + arr[i].Value);
}
}
}输出结果
1 SUV 2 AUV 3 Electric Car 4 Utility Vehicle 5 Hatchback 6 Compact car
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短