0
我是C#的新手(根据Visual Studio 2013命令行使用C#5)。微软网站上的以下一些教程后,我遇到一个问题:无法添加元素到Hashtable
using System;
using System.Collections;
public class Hashtable {
public static void Main() {
Hashtable employees = new Hashtable();
employees.Add("111-222-333","Matt");
employees.Add("222-333-444","Steve");
employees.Add("123-432-123","Adam");
if(employees.ContainsKey("111-222-333")) {
string empName = (string) employees["111-222-333"];
Console.WriteLine("Employee 111-222-333's name is: " + empName);
}
else {
Console.WriteLine("Employee 111-222-333 is not in the hash table.");
}
}
}
当我尝试编译此,我得到它规定了一个错误:
“添加”,没有扩展方法“添加”接受型 的第一个参数‘哈希表’可以找到(是否缺少using指令或程序 集引用?)
我完全糊涂了。我找不到任何暗示我应该做出与众不同的事情。
不要调用你自己的类'Hashtable'。 –
这是一个简单的修复(愚蠢的举动)。谢谢。 – Matt
考虑使用支持泛型的[Dictionary](http://msdn.microsoft.com/zh-cn/library/xfhwa508(v = vs.110).aspx)。 – user2864740