Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create new list from existing list?

Tags:

c#

list

I have a list

List<Student>

class Student{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string School { get; set; }
}

I want to use above list and create or fill that data into

List<Person>

class Person{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

Help me..

Thanx

like image 641
Darshana Avatar asked Mar 20 '12 10:03

Darshana


1 Answers

That should do the trick

List<Person> persons = students.Select(student => new Person {FirstName = student.FirstName, LastName = student.LastName}).ToList();
like image 128
Guillaume Avatar answered Oct 23 '22 11:10

Guillaume