0
votes

I have a class:

public class Person
{
 public string Name {get;set;}
 public string Address {get; set;}
 public string DOB {get; set;}
}

A list:

List<Person> personList = new List<Person>();

This List contains 4 Person objects with names "Person1", "Person2", "Person3" and "Person4" respectively and all other values for the properties.

Now I have another class:

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();

Now my question is: How do I map the personList to Citizen. I want to load all the values from the list to the citizen object. Please help.

1

1 Answers

0
votes

You classes should look like this

   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;}
    }