【发布时间】:2013-08-04 15:51:38
【问题描述】:
我正在尝试在字典数组列表中添加条目,但我不知道在主函数的 People 类中设置哪些参数。
public class People : DictionaryBase
{
public void Add(Person newPerson)
{
Dictionary.Add(newPerson.Name, newPerson);
}
public void Remove(string name)
{
Dictionary.Remove(name);
}
public Person this[string name]
{
get
{
return (Person)Dictionary[name];
}
set
{
Dictionary[name] = value;
}
}
}
public class Person
{
private string name;
private int age;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
}
使用这个似乎给我错误
static void Main(string[] args)
{
People peop = new People();
peop.Add("Josh", new Person("Josh"));
}
错误 2 方法 'Add' 没有重载需要 2 个参数
【问题讨论】:
-
你必须传递你在重载的 Add 方法中定义的参数
标签: c# class collections dictionary