Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
LINQ Partitioning: Take, Skip, TakeWhile, Chunk and Take(Range)
Why TakeWhile is not a filter, correct paging with Skip and Take and the silent rule of ordering, how TakeLast/SkipLast read to the end, Take(Range) from .NET 6 versus array slicing, splitting into batches with Chunk, and exactly how much of the source the partitioning operators read.
LINQ Element Operators: First, Last, Single, ElementAt and OrDefault
The First, Last, Single and ElementAt families and their OrDefault siblings; how 0 gets confused with 'not found' on value types, .NET 6's default value parameter and Index overloads, the difference in intent between First and Single, and nullable warnings.
Projection with LINQ: Select, SelectMany and Anonymous Types
One-to-one projection with Select and one-to-many with SelectMany; mapping to DTOs, keeping parent data with a result selector, the Cartesian product, the equality and with rules of anonymous types, and tuple versus record outside a method.
Filtering and Sorting with LINQ: Where, OrderBy, ThenBy and Reverse
Where and its index overload, why a second OrderBy wipes out the first, multi-key sorting with ThenBy, stable OrderBy versus unstable List.Sort, culture-sensitive string ordering, and how Reverse differs from OrderByDescending.
LINQ Deferred Execution: When Does a Query Run? IEnumerable and IQueryable
Why a LINQ query runs when it is iterated rather than when it is defined, element-by-element streaming, immediate and buffering operators, the cost of multiple enumeration, and the IEnumerable versus IQueryable split through Func and expression trees.
What Is LINQ? Query Syntax and Method Syntax in C#
What LINQ changes about the queries we used to write with loops, the C# 3.0 features behind it, how the compiler translates query syntax into method calls, when to pick which notation, and the first pitfalls.
C# 13–14 and .NET 9–10: OrderedDictionary, params Collections and More
Why Dictionary promises no order and .NET 9's generic OrderedDictionary, .NET 10's index-returning TryAdd/TryGetValue, PriorityQueue.Remove, allocation-free alternate lookup, C# 13 params collections and C# 14 extension members and span conversions.
C# 11–12 and .NET 7–8: Generic Math, Frozen and Collection Expressions
The generic sum you couldn't write in C# 10, generic math with static abstract members and INumber<T>; FrozenDictionary and FrozenSet, built once and read many times, measured with BenchmarkDotNet; square-bracket collection expressions, spread and CollectionBuilder.
Generic Variance in C#: Covariance and Contravariance (in and out)
Why can't a List<EBook> be a List<Book> when it can be an IEnumerable<Book>? The hole in array covariance, covariance with out, contravariance with in, variance in delegates, the limits of the rules and the cast trap CS0266 suggests.
Immutable Collections in C# and Choosing the Right Collection
The difference between a read-only view and real immutability, structural sharing in ImmutableList, builders, ImmutableArray versus ImmutableList measured with BenchmarkDotNet, and choosing the right collection with a complexity map.
C# Collection Interfaces: IEnumerable, ICollection, IList and yield return
What IEnumerable, ICollection, IList and the IReadOnly* interfaces promise and what they don't; why an array throws on Add, exposing an internal list safely, choosing parameter types and writing lazy iterators with yield return.
Sorted Collections in C#: SortedList, SortedDictionary, SortedSet and IComparer
A book silently lost from a SortedSet when the comparer returns zero, and the tie-breaking second criterion. SortedDictionary on a red-black tree, SortedList with two sorted arrays and when to pick which; Min, Max and the live GetViewBetween on SortedSet; IComparer, culture-sensitive string order and broken comparer traps.