获取或设置与C#中的StringDictionary中的指定键关联的值
要获取或设置与StringDictionary中的指定键关联的值,代码如下-
示例
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary strDict = new StringDictionary ();
strDict.Add("A", "Books");
strDict.Add("B", "Electronics");
strDict.Add("C", "Appliances");
strDict.Add("D", "Pet Supplies");
strDict.Add("E", "Clothing");
strDict.Add("F", "Footwear");
Console.WriteLine("Value associated with key D = "+strDict["D"]);
Console.WriteLine("Value associated with key F = "+strDict["F"]);
}
}输出结果
这将产生以下输出-
Value associated with key D = Pet Supplies Value associated with key F = Footwear
示例
让我们看另一个例子-
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary strDict = new StringDictionary ();
strDict.Add("A", "Books");
strDict.Add("B", "Electronics");
strDict.Add("C", "Appliances");
strDict.Add("D", "Pet Supplies");
strDict.Add("E", "Clothing");
strDict.Add("F", "Footwear");
Console.WriteLine("Value associated with key D = "+strDict["D"]);
Console.WriteLine("Value associated with key F = "+strDict["F"]);
strDict["F"] = "HDD";
Console.WriteLine("Value associated with key F (UPDATED) = "+strDict["F"]);
}
}输出结果
这将产生以下输出-
Value associated with key D = Pet Supplies Value associated with key F = Footwear Value associated with key F (UPDATED) = HDD
热门推荐
10 18岁简短祝福语经典
11 男友人新婚祝福语简短
12 公司年会亲属祝福语简短
13 幼儿祝福语押韵句子简短
14 鲜花卡片简短开业祝福语
15 宝宝新生入学祝福语简短
16 女神节日简短祝福语大全
17 朋友入伙搬家祝福语简短
18 过节文案成语祝福语简短