hashTable(哈希表)的基本用法

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();
           
        }
    }
}
原文地址:https://www.cnblogs.com/Lhuatao/p/3526741.html