software master at the intersection of technology, science and art



query expressions

Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. With LINQ, a query is now a first-class language construct, just like classes, methods, events and so on.

Query expressions are written in a declarative query syntax. By using query syntax, you can perform even complex filtering, ordering, and grouping operations on data sources with a minimum of code. You use the same basic query expression patterns to query and transform data in SQL databases, ADO.NET Datasets, XML documents and streams, and .NET collections. See Linq Query Expressions(C# Programming Guide) for more details.

// Specify the data source.
int[] scores = new int[] { 97, 92, 81, 60 };
// Define the query expression.
IEnumerable scoreQuery =
from score in scores
where score > 80
select score;
// Execute the query. -note that the code query expression is not executed until here
foreach (int i in scoreQuery)
{ Console.Write(i + " "); }