Reputation: 1633
I have a question here. Lets say I have these two classes
class Person
{
int person_id;
string name;
Address address;
}
class Address
{
int address_id;
string street;
}
and I have list of Person data in List<Person> people = new List<Person>();
.
Now I want to copy all of the address
in people
to a new address list List<Address> addresses = new List<Address>();
. How can I achieve this?
Upvotes: 0
Views: 744
Reputation: 101681
You want to do a projection which means take the objects and transform them into another form:
List<Address> addresses = people.Select(p => p.Address).ToList();
Upvotes: 4