IT入门 > 教程 > C#教程 > 数组和集合 >
  • C#哈希表添加元素 日期:2025-10-15 点击:5367 数组和集合

    在C#里,哈希表(Hashtable)可用来存储键值对。添加元素时,需用Add方法。 // 引入命名空间using System;using System.Collections;class Program{ static void Main() { // 创建哈希表 Hashtable ht = new Hashtabl...

  • C#哈希表删除元素 日期:2025-10-15 点击:2422 数组和集合

    在C#中,可通过Remove方法从哈希表里删除元素。 // 引入命名空间using System;using System.Collections;class Program{ static void Main() { // 创建哈希表 Hashtable ht = new Hashtable(); ht.Add("key1", "value1"); ht.Ad...

  • C#哈希表遍历 日期:2025-10-15 点击:6273 数组和集合

    在C#里,哈希表(Hashtable)可存储键值对,遍历哈希表是常见操作。可通过foreach语句实现。 using System;using System.Collections;class Program{ static void Main() { Hashtable ht = new Hashtable(); ht.Add("key1"...

  • C#哈希表查找元素 日期:2025-10-15 点击:3816 数组和集合

    C#中,可借助键查找哈希表中的元素。使用ContainsKey方法判断键是否存在,若存在用索引器获取对应值。 using System;using System.Collections;class Program{ static void Main() { Hashtable ht = new Hashtable(...