将指定的键和值添加到C#中的ListDictionary中
要将指定的键和值添加到ListDictionary中,代码如下-
示例
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
ListDictionary dict = new ListDictionary();
dict.Add("1", "One");
dict.Add("2", "Two");
dict.Add("3", "Three");
dict.Add("4", "Four");
dict.Add("5", "Five");
Console.WriteLine("ListDictionary key-value pairs...");
IDictionaryEnumerator demoEnum = dict.GetEnumerator();
while (demoEnum.MoveNext())
Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
}
}输出结果
这将产生以下输出-
ListDictionary key-value pairs... Key = 1, Value = One Key = 2, Value = Two Key = 3, Value = Three Key = 4, Value = Four Key = 5, Value = Five
示例
现在让我们来看另一个示例-
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main(){
ListDictionary listDict = new ListDictionary();
listDict.Add("1", 100);
listDict.Add("2", 200);
listDict.Add("3", 300);
listDict.Add("4", 400);
listDict.Add("5", 500);
listDict.Add("6", 600);
listDict.Add("7", 700);
listDict.Add("8", 800);
listDict.Add("9", 900);
listDict.Add("10", 1000);
ICollection col = listDict.Keys;
Console.WriteLine("Display all the keys...");
foreach(String s in col){
Console.WriteLine(s);
}
}
}输出结果
这将产生以下输出-
Display all the keys... 1 2 3 4 5 6 7 8 9 10
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短