C# hashtable 哈希表

实现了,ICollection和IEnumerable接口。
     方法
     Add(object,object)
     通过索引来获得值    

我们学习吧...

View Code
 1 using System;

 2 using System.Collections;

 3  public class HashTable

 4  {

 5      public static void Main()

 6      {

 7          Hashtable ht = new Hashtable();

 8          ht.Add("three","石头");

 9          ht.Add(5,5);

10          ht.Add(9,"hdsuooe");

11          foreach( object c in ht.Values)

12         {

13           Console.WriteLine(c.ToString());

14          }

15          foreach(object d in ht.Keys)

16         {

17           Console.WriteLine(d.ToString() );

18          }

19         

20  }

21  public static void Test()

22 {

23      Hashtable ht = new Hashtable();

24      ht.Add("one","one");

25      ht.Add("two",2);

26      ht.Add(3,3);

27      //读取值

28      object o = ht[0];

29      ht[0] = "哈哈";

30      Console.WriteLine(ht[0]);

31      var collection = ht.Keys;

32      var collection1 = ht.Values;

33      foreach(object a in collection)

34     {

35          Console.WriteLine(a.ToString());

36      }

37      foreach(object b in collection1)

38     {

39        Console.WriteLine(b.ToString());

40      }

41   }

42     

43 }

44  

 

你可能感兴趣的:(Hashtable)