概述
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]);
}
}
}
}