我正在尝试在字典数组列表中添加条目,但我不知道要在主函数的 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 方法“添加”没有重载需要 2 个参数