我有一个班级:
public class Person
{
public string Name {get;set;}
public string Address {get; set;}
public string DOB {get; set;}
}
清单:
List<Person> personList = new List<Person>();
此列表包含4个Person对象,分别名称为“Person1”,“Person2”,“Person3”和“Person4”以及属性的所有其他值。
现在我有了另一堂课:
public class Citizen
{
public Person Abc1 {get; set;}= new Person{Name="Person1"};
public Person Abc2 {get; set;}= new Person{Name="Person2"};
public Person Abc3 {get; set;}= new Person{Name="Person3"};
public Person Abc4 {get; set;}= new Person{Name="Person4"};
}
var citizen = new Citizen();
现在我的问题是:如何将personList映射到Citizen。我想将列表中的所有值加载到citizen对象。请帮忙。
答案 0 :(得分:0)
你的课程应该是这样的
public class Citizen
{
public static List<Person> personList = new List<Person>() {
new Person{Name="Person1"},
new Person{Name="Person2"},
new Person{Name="Person3"},
new Person{Name="Person4"}
};
}
public class Person
{
public string Name {get;set;}
public string Address {get; set;}
public string DOB {get; set;}
}