概述

Hashtable用来存储键值对数据。

  • Add() 添加元素
  • Remove() 移除元素
  • Count 键值对个数
  • Keys 键值集合
示例
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable ht = new Hashtable();
            ht.Add(0, "c");
            ht.Add(1, "c#");
            ht.Add(2, "php");
            ht.Add(3, "java");
            ht.Add(4, "java");
            ht[5] = "rust";
            ht.Remove(0);
            Console.WriteLine("ht键值对个数:{0}",ht.Count);
            if (ht.Contains(1))
            {
                Console.WriteLine("Contains");
            }
            foreach (var item in ht.Keys)
            {
                Console.WriteLine(ht[item]);
            }
        }
    }
}
  • 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.