将键和值添加到C#中的StringDictionary中
要将键和值添加到StringDictionary中,代码如下-
示例
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary strDict = new StringDictionary();
strDict.Add("A", "John");
strDict.Add("B", "Andy");
strDict.Add("C", "Tim");
strDict.Add("D", "Ryan");
strDict.Add("E", "Kevin");
strDict.Add("F", "Katie");
strDict.Add("G", "Brad");
Console.WriteLine("StringDictionary elements...");
foreach(DictionaryEntry de in strDict) {
Console.WriteLine(de.Key + " " + de.Value);
}
}
}输出结果
这将产生以下输出-
StringDictionary elements... a John b Andy c Tim d Ryan e Kevin f Katie g Brad
示例
让我们看另一个例子-
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary strDict = new StringDictionary();
strDict.Add("1", "Electric Cars");
strDict.Add("2", "SUV");
strDict.Add("3", "AUV");
Console.WriteLine("StringDictionary elements...");
foreach(DictionaryEntry de in strDict) {
Console.WriteLine(de.Key + " " + de.Value);
}
}
}输出结果
这将产生以下输出-
StringDictionary elements... 1 Electric Cars 2 SUV 3 AUV
热门推荐
10 新年给妈妈简短祝福语
11 生了女孩祝福语简短的
12 新人结婚父母祝福语简短
13 宝宝生病简短祝福语大全
14 祝福语女友文案简短霸气
15 感动妈妈的祝福语简短
16 对别人新年祝福语简短
17 升学祝福语简短的个性
18 表达家人的祝福语简短