Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy List of objects into List in another object
    primarykey
    data
    text
    <p>I have been trying to figure this out in c#. I just started doing C# so I would appreciate your help.</p> <p>I want to copy a list of Objects to a list in another object.</p> <p>It looks something like this. </p> <pre><code>class Person { public String fName; public String lName; public List&lt;House&gt; housesOwned = new List&lt;House&gt;(); public Student(String FName, String LName) { this.fName = FName; this.lName = LName; } } class House { public String Address; public House (String ad1){ this.Address1 = ad1; } } </code></pre> <p>Now, in my Form I created a list of objects type House (it has 2 objects of type House to be precise), which are the two houses that the person owns.</p> <p>Something like : <code>List&lt;House&gt; housesList = new List&lt;House&gt;;</code></p> <p>Basically what I am trying to do is to copy the <code>List&lt;House&gt; housesList</code> created in the form to the <code>List&lt;House&gt; housesOwned</code> which is the list in the object Person. This will happen when pressing the submit button. So far I got this:</p> <pre><code>List&lt;Person&gt; person = new List&lt;Person&gt;(); // declared at the beginning of the form ..... private void submit_Click(object sender, EventArgs e) { person.Add(new Person(personName.Text, personLName.Text)); //I do not know what comes next to copy the list housesList to the list housesOwned MessageBox.Show("Done!"); } </code></pre> <p>I want the objects houses to be copied containing their addresses. Thank you very much for all your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload