c# Convert LINQ var result to actual type
        Posted  
        
            by DrBob
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by DrBob
        
        
        
        Published on 2010-04-14T03:27:50Z
        Indexed on 
            2010/04/14
            3:33 UTC
        
        
        Read the original article
        Hit count: 263
        
In c#, Given the following code:
public class Person
{
    public int PersonID { get; set; }
    public int Age { get; set; }
    public string Name { get; set; }
}
and
    List<Person> people = new List<Person>();
    for (int i = 0; i != 15; i++)
    {
        Person p = new Person();
        p.PersonID = i;
        p.Age = i * 12;
        p.Name = "Name " + i;
        people.Add(p);
    }
    var sortedPeople = from qPeople in people
                       where qPeople.Age > 0 && qPeople.Age < 25 || qPeople.Age > 100
                       orderby qPeople.Age descending
                       select qPeople;
Can I load the results of sortedPeople back into a List<Person> without a loop?
Thanks.
© Stack Overflow or respective owner