获取包含哈希表C#中的键的ICollection
要获取包含Hashtable中的键的ICollection,代码如下-
示例
using System;
using System.Collections;
public class Demo {
public static void Main() {
Hashtable hash = new Hashtable();
hash.Add("A", "Electronics");
hash.Add("B", "Appliances");
hash.Add("C", "Pet Supplies");
hash.Add("D", "Books");
hash.Add("E", "Toys");
hash.Add("F", "Footwear");
hash.Add("G", "Clothing");
ICollection col = hash.Keys;
foreach(string str in col)
Console.WriteLine(str + ": " + hash[str]);
}
}输出结果
这将产生以下输出-
G: Clothing A: Electronics B: Appliances C: Pet Supplies D: Books E: Toys F: Footwear
示例
让我们看另一个例子-
using System;
using System.Collections;
public class Demo {
public static void Main() {
Hashtable hash = new Hashtable();
hash.Add(1, "AB");
hash.Add(2, "CD");
hash.Add(3, "EF");
hash.Add(4, "GH");
hash.Add(5, "IJ");
hash.Add(6, "KL");
hash.Add(7, "MN");
ICollection col = hash.Keys;
foreach(int str in col)
Console.WriteLine("Key = " + str + ", Value = " + hash[str]);
}
}输出结果
这将产生以下输出-
Key = 7, Value = MN Key = 6, Value = KL Key = 5, Value = IJ Key = 4, Value = GH Key = 3, Value = EF Key = 2, Value = CD Key = 1, Value = AB
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短