C#之哈希表学习案例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Hashtable_test
{
    class Program
    {
        static void Main()
        {
            Hashtable Ht = new Hashtable();    //创建一个Hashtable实例
            Ht.Add("E", "e");          //添加key/value键值对
            Ht.Add("A","a");
            Ht.Add("C","c");
            Ht.Add("B", "b");
            string s = (string)Ht["A"];
            if (Ht.Contains("E"))
            {
                //判断哈希表是否包含特定键,返回值为true或false
                Console.WriteLine("the E key:Exist");
            }
            Ht.Remove("C");     //移除一个key/value键值对
            Console.WriteLine(Ht["A"]);//此处输出a
            Ht.Clear();      //移除所有元素
            Console.WriteLine(Ht["A"]);         //此处将不会有任何输出
        }
    }
}

原文地址:https://www.cnblogs.com/zztong/p/6695237.html