zoukankan      html  css  js  c++  java
  • 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  
  • 相关阅读:
    第十九天:类和对象
    第十五天:模块
    十四天:匿名函数
    十四天作业
    第十三天:迭代器、递归
    十二天:闭包和装饰器
    一个炒鸡简单的购物车
    十一天
    第十天
    第十天作业
  • 原文地址:https://www.cnblogs.com/QLJ1314/p/2622911.html
Copyright © 2011-2022 走看看