| More complicated example: var seniorMales = from c in customer where c.age > 65 && c.Sex == “male” select new {c.FirstName, c.Lastname, c.Age} foreach(var customer in seniorMales)
{
Console.WriteLine(customer.Firstname + “ “ + customer.Lastname);
} Why would I create a class/struct for that use case? Side note: this is why I find ORMs in most languages besides C# useless. Here, “customers” can represent an in memory List, a Sql table or a MongoDB collection and the LINQ expression will be translated appropriately to the underlying query syntax. The “ORM” is integrated into the language and yes anyone can write a LINQ provider. |