Review extension methods from the System.Linq namespace. Learn to write queries directly in programs.

LINQ. The bird calls out in search of a mate. It queries the surrounding area with its bird song. With LINQ we formulate queries in our programs.

Methods. In a query, we ask for something. We ask for an array to be filtered or sorted or changed. LINQ is Language Integrated Query—here are methods that encode these requests.AggregateAllAnyAsEnumerableAsParallelAsQueryableAverageCastConcatContainsCountDefaultIfEmptyDistinctElementAt, ElementAtOrDefaultExceptFirstFirstOrDefaultGroupByGroupJoinIntersectJoinLast, LastOrDefaultMax, MinOfTypeOrderBy, OrderByDescendingReverseSelectSelectManySequenceEqualSingleSingleOrDefaultSkip, SkipWhileSumTake, TakeWhileToArrayToDictionaryToListToLookupUnionWhereZip

Query keywords. Query expressions use a whole new set of keywords. These are contextual keywords. This means they only have meaning in query expressions.ascending, descendinggroupjoinletorderbyselect new

Enumerable. The Enumerable type has some useful static methods. If you need an IEnumerable collection of a range or a repeated element, consider Range or Repeat.Range, Repeat, Empty

Extension methods. This is a special syntax form in C#. We can call a method on a variable like it is an instance method. But it is not on the class. It is specified in a separate place.Extension

Notes, syntactic sugar. LINQ can be seen as a form of syntactic sugar. Queries could be written with for-loops. But when a program is easier to read and write, often it is better.

A summary. LINQ is a powerful feature. Its methods and query expressions often improve the readability of programs. And they sometimes lead to new, delayed, superior algorithms.
Dot Net Perls
© 2007-2020 Sam Allen. Every person is special and unique. Send bug reports to