1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 |
using
System; using
System.Collections.Generic; using
System.Linq; using
System.Text; using
System.Collections; namespace
hashTableTest { class
Program { static
void
Main( string [] args) { Hashtable ht = new
Hashtable(); //哈希表元素的添加 ht.Add(1, "星期一" ); ht.Add(2, "星期二" ); ht.Add(3, "星期三" ); ht.Add(4, "星期四" ); ht.Add(5, "星期五" ); ht.Add(6, "星期六" ); ht.Add(7, "星期日" ); //哈希表元素的获取 Console.WriteLine(ht[1]); //哈希表元素的删除 ht.Clear(); //哈希表元素的修改 ht[1] = "礼拜1" ; //判断是否存在哈希元素返回值为True/false ht.Contains(1); ht.ContainsKey(1); //根据KEY值判断 结果为True ht.ContainsValue( "星期一" ); //根据Value值判读 结果为True //哈希表元素的遍历 foreach
(DictionaryEntry my in
ht) { Console.WriteLine(my.Key); Console.WriteLine(my.Value); } Console.ReadLine(); } } } |
原文:http://www.cnblogs.com/Lhuatao/p/3526741.html