13.5. Applying LINQ Queries to Collection Objects

Beyond pulling results from a simple array of data, LINQ query expressions can also manipulate data within members of the System.Collections.Generic namespace, such as the List<T> type. Create a new Console Application project named LinqOverCollections, and define a basic Car class that maintains a current speed, color, make, and pet name as shown in the following code:

class Car
{
  public string PetName {get; set;}
public string Color {get; set;}
  public int Speed {get; set;}
  public string Make {get; set;}
}

Now, within your Main() method define a local List<T> variable of type Car, and make use of object initialization syntax to fill the list with a handful of new Car objects:

static void Main(string[] ...

Get Pro C# 2010 and the .NET 4 Platform, Fifth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.