C#中获取或设置StringDictionary中指定键处的值
要获取或设置StringDictionary中指定键的值,代码如下-
示例
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary myDict = new StringDictionary();
myDict.Add("1", "Tablet");
myDict.Add("2", "Desktop");
myDict.Add("3", "Speakers");
myDict.Add("4", "Laptop");
myDict.Add("5", "Notebook");
myDict.Add("6", "Ultrabook");
myDict.Add("7", "HDD");
myDict.Add("8", "SDD");
myDict.Add("9", "Headphone");
myDict.Add("10", "Earphone");
Console.WriteLine("Value for key 5 = "+myDict["5"]);
}
}输出结果
这将产生以下输出-
Value for key 5 = Notebook
示例
让我们看另一个例子-
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary myDict = new StringDictionary();
myDict.Add("1", "Tablet");
myDict.Add("2", "Desktop");
myDict.Add("3", "Speakers");
myDict.Add("4", "Laptop");
myDict.Add("5", "Notebook");
myDict.Add("6", "Ultrabook");
myDict.Add("7", "HDD");
myDict.Add("8", "SDD");
myDict.Add("9", "Headphone");
myDict.Add("10", "Earphone");
Console.WriteLine("Value for key 5 = "+myDict["5"]);
myDict["5"] = "Flash Drive";
Console.WriteLine("Value for key 5 [Updated] = "+myDict["5"]);
}
}输出结果
这将产生以下输出-
Value for key 5 = Notebook Value for key 5 [Updated] = Flash Drive
热门推荐
10 新年祝福语简短聪明可爱
11 顾客简短祝福语大全集
12 生女儿的祝福语简短
13 考试祝福语日文简短版
14 生日宝宝祝福语简短独特
15 生日祝福语 简短独特老弟
16 老人过大寿祝福语简短
17 佛教生日祝福语简短大全
18 儿女的生日祝福语简短