根据我的转帖的C版的例子.重写的C#版! 首先定义一个Hash类 public class Hash : DictionaryBase { public string this[string key] { set { Dictionary[key] = value; } get { return (string)Dictionary[key]; } } public void Add(string key, string value) { Dictionary.Add(key, value); } public void Remove(string key) { Dictionary.Remove(key); } public bool Contains(string key) { return Dictionary.Contains(key); } } 具体部分 /// <summary> /// 哈希表 /// </summary> public class Test3 { private void menu() { Console.WriteLine(); Console.Write("/n* * * * * * * * * * * * * * * * * * * * * * * * * */n"); Console.Write(" 1 ------- 查找关键字/n"); Console.Write(" 2 ------- 插入关键字/n"); Console.Write(" 3 ------- 删除关键字/n"); Console.Write(" 4 ------- 打印哈希表/n"); Console.Write(" 5 ------- 退出/n"); Console.Write("* * * * * * * * * * * * * * * * * * * * * * * * * */n"); Console.WriteLine(); } private bool SearchHash(Hash H, string K) { return H.Contains(K); } public bool InsertHash(Hash H, string K, string V) { if (SearchHash(H, K)) return false; else { H.Add(K, V); return SearchHash(H, K); } } private bool DeleteHash(Hash H, string K) { if (SearchHash(H, K)) { H.Remove(K); return !SearchHash(H, K); } else { return false; } } private void PrintHash(Hash H) { foreach (DictionaryEntry ent in H) { Console.WriteLine(string.Format("{0}:{1}", ent.Key, ent.Value)); } } public void menuselect(Hash H) { int k; bool done = true; while (done) { menu(); Console.Write("请选择一个功能: "); k = Convert.ToInt32(Console.ReadLine()); switch (k) { case 1: { Console.Write("/n输入查找数据: "); string K=Convert.ToString(Console.ReadLine()); if (SearchHash(H,K)) Console.Write("数据已找到!"); else Console.Write("数据没找到!/n"); break; } case 2: { Console.Write("/n输入插入数据: "); string K = Convert.ToString(Console.ReadLine()); if (InsertHash(H, K,"hello")) Console.Write("插入成功/n"); else Console.Write("此数据已经存在!/n"); break; } case 3: { Console.Write("/n输入删除数据: "); string K = Convert.ToString(Console.ReadLine()); if (!DeleteHash(H, K)) Console.Write("删除数据不存在!/n"); else Console.Write("删除成功"); break; } case 4: PrintHash(H); break; case 5: done = false; break; } } } }