Core Operators at a Glance
LINQ's surface area is large, but day-to-day work draws from a small, stable core: Where for filtering, Select for projection, OrderBy/OrderByDescending/ThenBy for sorting, GroupBy for bucketing, and Join/GroupJoin for combining sequences. Every one of these operators is an extension method defined on IEnumerable<T> (in System.Linq) or IQueryable<T> (in System.Linq for the queryable variants), which is why they're available on arrays, List<T>, DbSet<T>, and virtually any collection type without any special setup beyond a using System.Linq; directive.
Cricket analogy: It's like a captain's core toolkit — field placements (Where, filtering the ground), batting order (OrderBy, sorting), and bowling changes (GroupBy, bucketing by phase) — a small set of levers that work identically whether it's a T20 or a Test match, the way LINQ operators work identically across arrays, lists, or database sets.
Filtering, Ordering, and Projection Syntax
For quick lookup: Where(x => condition) filters; OrderBy(x => key) sorts ascending and OrderByDescending(x => key) sorts descending, with ThenBy/ThenByDescending providing secondary sort keys after an initial OrderBy; Select(x => newShape) projects each element to a new form, and Select(x => x.Collection).SelectMany(c => c) or the two-argument SelectMany(x => x.Collection, (x, c) => ...) flattens nested collections. Skip(n) and Take(n) are the standard pagination pair, almost always used together as .Skip(pageIndex * pageSize).Take(pageSize) after an OrderBy to guarantee a stable, deterministic page order.
Cricket analogy: It's like filtering a season's matches to only away games (Where), sorting by run margin descending with net run rate as tiebreak (OrderByDescending then ThenBy), and paginating a long list of matches ten at a time for a mobile app (Skip/Take) — the exact recipe behind any cricket stats app's match list.
// Quick-reference one-liners
var active = items.Where(x => x.IsActive);
var byName = items.OrderBy(x => x.Name).ThenBy(x => x.Id);
var names = items.Select(x => x.Name);
var flat = orders.SelectMany(o => o.Items);
var page2 = items.OrderBy(x => x.Id).Skip(20).Take(10);
var total = items.Sum(x => x.Amount);
var count = items.Count(x => x.IsActive);
var avg = items.Average(x => x.Score);
var max = items.Max(x => x.Score);
var firstOrNull = items.FirstOrDefault(x => x.Id == 5);
var exists = items.Any(x => x.IsActive);
var allMatch = items.All(x => x.Score > 0);
var distinct = items.Select(x => x.Category).Distinct();
var grouped = items.GroupBy(x => x.Category);
Aggregation, Element, and Set Operators
Aggregate operators reduce a sequence to a single value: Count() (or Count(predicate)), Sum(selector), Average(selector), Min/Max(selector), and the fully general Aggregate(seed, func) for custom accumulation logic not covered by the built-ins. Element operators fetch a single item by position or condition — First/FirstOrDefault, Single/SingleOrDefault (which additionally validates uniqueness), Last/LastOrDefault, and ElementAt(index)/ElementAtOrDefault(index) — while set operators compare whole sequences: Distinct() removes duplicates, Union() combines and de-duplicates two sequences, Intersect() keeps only shared elements, and Except() keeps elements in the first sequence absent from the second.
Cricket analogy: It's like reducing an entire innings to one number — total runs (Sum), highest individual score (Max), average per wicket (Average) — while a element lookup like 'who's the No. 4 batter?' is ElementAt, and comparing two teams' player lists with Intersect finds players who've played for both.
Single() and SingleOrDefault() throw an InvalidOperationException if more than one element matches, not just if none match — don't reach for Single as a synonym for First when you actually expect (and would tolerate) multiple matches; use First/FirstOrDefault instead.
Every LINQ operator listed here is deferred except the aggregate/element operators (Count, Sum, First, ToList, ToArray, ToDictionary, etc.), which force immediate execution — keep this split in mind when scanning code for where a query actually 'runs'.
- Where filters, Select projects, OrderBy/ThenBy sorts, GroupBy buckets, SelectMany flattens — the five operators behind most queries.
- Skip(n).Take(m) after an OrderBy is the standard, deterministic pagination pattern.
- Sum/Average/Min/Max/Count reduce a sequence to a single value; Aggregate handles custom reduction logic.
- First/Single/Last (and their OrDefault variants) fetch a single element; Single additionally enforces uniqueness.
- Distinct/Union/Intersect/Except compare whole sequences using the default or a supplied equality comparer.
- Operators that return a scalar or a collection type like List<T> (Count, Sum, ToList) execute immediately; everything returning IEnumerable<T>/IQueryable<T> is deferred.
Practice what you learned
1. Which combination is the standard LINQ pagination pattern?
2. What does ThenBy do when chained after OrderBy?
3. What distinguishes Single() from First() when exactly one element matches a condition?
4. Which of these LINQ operators executes immediately rather than being deferred?
Was this page helpful?
You May Also Like
Common LINQ Patterns
The recurring LINQ idioms — filtering, flattening, grouping, and joining — that show up in almost every C# codebase.
LINQ Interview Questions
The conceptual questions, coding challenges, and gotchas that come up most often when LINQ is tested in C# interviews.
LINQ Best Practices
Practical guidelines for writing readable, performant, and maintainable LINQ — from query composition to IQueryable pitfalls.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics