获取或设置与C#中的哈希表中的指定键关联的值
要获取或设置与Hashtable中的指定键关联的值,代码如下-
示例
using System;
using System.Collections;
public class Demo {
public static void Main() {
Hashtable hash = new Hashtable();
hash.Add("1", "AB");
hash.Add("2", "BC");
hash.Add("3", "DE");
hash.Add("4", "EF");
hash.Add("5", "GH");
hash.Add("6", "IJ");
hash.Add("7", "KL");
hash.Add("8", "MN");
hash.Add("9", "OP");
hash.Add("10", "QR");
Console.WriteLine("Value at key 3 = "+hash["3"]);
}
}输出结果
这将产生以下输出-
Value at key 3 = DE
示例
让我们看另一个例子-
using System;
using System.Collections;
public class Demo {
public static void Main() {
Hashtable hash = new Hashtable();
hash.Add("1", "AB");
hash.Add("2", "BC");
hash.Add("3", "DE");
hash.Add("4", "EF");
hash.Add("5", "GH");
hash.Add("6", "IJ");
hash.Add("7", "KL");
hash.Add("8", "MN");
hash.Add("9", "OP");
hash.Add("10", "QR");
Console.WriteLine("Value at key 3 = "+hash["3"]);
hash["3"] = "UV";
Console.WriteLine("Value at key 3 (UPDATED) = "+hash["3"]);
}
}输出结果
这将产生以下输出-
Value at key 3 = DE Value at key 3 (UPDATED) = UV
热门推荐
10 早日回国祝福语简短英语
11 横幅家庭生日祝福语简短
12 安徽疫情祝福语简短英语
13 送弟弟中秋祝福语简短
14 家人长辈新春祝福语简短
15 金店立秋祝福语简短英文
16 团队海报祝福语简短英语
17 诗词送行祝福语大全简短
18 六一互换礼物祝福语简短