LINQ to Objects extends any type that inherits from IEnumerable (which is almost every collection class in .NET, from simple Arrays to List<T>) to support query operations similar to those available in SQL. We can write queries using any of the built-in Standard Query Operators, or add our own operators if we need to. The standard operators cover a wide variety of categories, at present there are over fifty that form the backbone of LINQ. To get an idea of their scope, here is a list of those operators available to us –
Operator Type | Operator Name |
Aggregation | Aggregate, Average, Count, LongCount, Max, Min, Sum |
Conversion | Cast, OfType, ToArray, ToDictionary, ToList, ToLookup, ToSequence |
Element | DefaultIfEmpty, ElementAt, ElementAtOrDefault, First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault |
Equality | EqualAll |
Generation | Empty, Range, Repeat |
Grouping | GroupBy |
Joining | GroupJoin, Join |
Ordering | OrderBy, ThenBy, OrderByDescending, ThenByDescending, Reverse |
Partitioning | Skip, SkipWhile, Take, TakeWhile |
Quantifiers | All, Any, Contains |
Restriction | Where |
Selection | Select, SelectMany |
Set | Concat, Distinct, Except, Intersect, Union |
Most of the operators should be familiar if you have ever worked with a relational database writing queries in SQL.
One important distinction between writing SQL queries and LINQ queries is that the operator order is reversed. If you are used to Select-From-Where-OrderBy, it might take some time to overcome the muscle memory and move to From-Where-OrderBy-Select.
Add to favorites