LINQ (Language Integrated Query) is an expression that retrieves data from a data source. LINQ simplifies this situation by offering a consistent model for working with data across various kinds of data sources and formats. In a LINQ query, you are always working with objects. You use the same basic coding patterns to query and transform data in XML documents, SQL databases, ADO.NET Datasets, .NET collections, and any other format for which a LINQ provider is available.
Generating Dictionary From IEnumerable
Getting distinct values (using the Distinct method)
Mapping array by Select clause
Query result will be enumerable object containing lengths of strings in input array. In this example this would be values 14, 10, 10, 24. x in the query is iterating variable where will be stored each object from the input array.
OrderBy clause orders the output by the value returned from the clause. In this example it is Length of each string. Default output order is ascending. If you need descending you could specify Descending keyword after clause.
We can project multiple result at once too
Selecting from array with simple condition
Query will be enumerable object containing Stack Overflow and Super User. x in the query is iterating variable where will be stored each object checked by Where clause.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0