Return Custom Class in LINQ

Here’s an example of how to use LINQ with a custom class:

static void GetPeople(int minAge, int maxAge)

{

    var people = CreatePersonList(1000);

 

    var peopleList = from p in people

                where p.Age >= minAge

                    && p.Age <= maxAge

                orderby p.Age,p.Name

                select p;

 

    foreach (Person p in peopleList)

    {

        Console.WriteLine("\r\nName: {0}\r\nAge: {1}\r\nGender: {2}\r\n", p.Name, p.Age, p.Gender);

    }

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s