我有一个班级Person
class Person
{
public string Active { get; set; }
public string Name { get; set; }
public string From { get; set; }
public string Age { get; set; }
public string Gender { get; set; }
public string Country { get; set; }
}
public Person(string active, string name, string from, string age, string gender, string country)
{
Active = active;
Name = name;
From = from;
Age = age;
Gender = gender;
Country = country;
}
我还有一个名为PersonList
class PersonList : Person
{
}
我的班级人员列表必须包含 ADD 的一个字段到我的列表视图,搜索 INDEX , NAME 和 ACTIVE 但我不知道如何从PersonList类中的Person类中获取值
当我在我的主脚本中尝试这样做时:
private void btnSubmit_Click(object sender, EventArgs e)
{
PersonList newPerson = new PersonList(
txtActive.Text,
txtName.Text,
txtFrom.Text,
txtAge.Text,
txtGender.Text,
txtCountry.Text);
if (newPerson.check())
erase();
}
我收到一个错误,告诉PersonList不包含一个带有11个Arguments的构造函数。
答案 0 :(得分:0)
与其他一些隐式继承构造函数的语言不同,它与C#中的情境不同。您需要明确告诉您需要继承构造函数。
换句话说,创建一个接受11个参数的构造函数,并通过base
public PersonList(string arg1, string arg2...) : base(arg1, arg2...)
答案 1 :(得分:-1)
class Person {
public string Active { get; set; }
public string Name { get; set; }
public string From { get; set; }
public string Age { get; set; }
public string Gender { get; set; }
public string Country { get; set; }
public Person(string active, string name, string from, string age, string gender, string country) {
Active = active;
Name = name;
From = from;
Age = age;
Gender = gender;
Country = country;
}
}
class PersonList : Person {
public PersonList(string active, string name, string from, string age, string gender, string country) : base(active, name, from, age, gender, country) {}
}
private void btnSubmit_Click(object sender, EventArgs e) {
PersonList newPerson = new PersonList(
txtActive.Text,
txtName.Text,
txtFrom.Text,
txtAge.Text,
txtGender.Text,
txtCountry.Text);
if (newPerson.check())
erase();
}