Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
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.
C# Queue, Stack, LinkedList and PriorityQueue: Collections That Work in Order
Queue<T> for FIFO, Stack<T> for LIFO and undo, LinkedList<T> for O(1) inserts and removals through nodes, and a small LRU cache built from LinkedList and Dictionary. The .NET 6 PriorityQueue: why UnorderedItems is unordered, why it is not stable for equal priorities, a fair queue with sequence numbers, and the N most expensive books with EnqueueDequeue.
C# Dictionary and HashSet: TryGetValue, Key Equality and Comparers
How a Dictionary finds a key with GetHashCode and Equals, and why a class key without equality bloats it. The differences between Add, the indexer, TryAdd and TryGetValue, counting in a single lookup with .NET 6 CollectionsMarshal, the mutable key trap, OrdinalIgnoreCase and the Turkish I trap, ordering, and HashSet set operations.