Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
What's New in C# 13: params Collections, Lock and Partial Properties
C# 13 next to its C# 10 equivalents: the new Lock type and the CS9216 trap, params collections with an allocation measurement, ref structs implementing interfaces and allows ref struct, partial properties, OverloadResolutionPriority, the \e escape and ^ indexes in initializers.
What's New in C# 12: Primary Constructors and Collection Expressions
C# 12 next to its C# 10 equivalents: why a primary constructor is a parameter rather than a property and the CS9124 warning, square-bracket collection expressions and spread, default lambda parameters, alias any type, inline arrays, the Experimental attribute and a note on interceptors.
What's New in C# 11: Raw Strings, required and List Patterns
How we wrote it in C# 10 and how we write it in C# 11: raw string literals and the culture trap, required members and SetsRequiredMembers, list patterns, generic math with its language and library legs, file-local types and UTF-8 literals.
C# Versions: A Short History from 1.0 to 10
The signature features, release dates and .NET pairings of every version from C# 1.0 to C# 10; compiling the same code with different LangVersion values to see how the compiler tells you which feature came from which version.
Unit Testing in C#: xUnit, Theory/InlineData and Testable Code
The hidden dependencies behind a flaky test, an xUnit test project, Fact and Assert, Theory/InlineData/MemberData, taking time from outside with IClock, and pitfalls like decimal InlineData and async void.
Dependency Injection Basics in C#: Lifetimes, the Container and Captive Dependencies
Constructor injection with Microsoft.Extensions.DependencyInjection, singleton/scoped/transient, the container's disposal duty, captive dependencies and ValidateScopes, multiple registrations, TryAdd and factories.
Performance in C#: Allocations, Structs and Measuring with BenchmarkDotNet
Why Stopwatch isn't enough, setting up BenchmarkDotNet 0.15.8 and reading its table, the measured difference between classes and structs, hidden allocations from boxing and closures, and benchmark pitfalls.
Source Generators in C#: Generating Code at Compile Time with IIncrementalGenerator
Writing an incremental generator that adds code during the build: the netstandard2.0 project and Roslyn version, the pipeline and caching, seeing the generated code, and the partial and hint name pitfalls.
Interop and unsafe Code in C#: P/Invoke, Pointers and fixed
AllowUnsafeBlocks and pointers, pinning against the GC with fixed, calling libc with DllImport, string marshalling, callbacks with function pointers, and keeping unsafe code small with NativeMemory and spans.
ref Returns, ref Locals, in Parameters and ref struct in C#
Moving values by reference instead of copying them: ref locals, ref returns, ref readonly, the defensive-copy trap with in parameters, readonly structs and writing your own ref struct.
Span<T> and Memory<T> in C#: Allocation-Free Parsing, stackalloc and ref struct Rules
Copy-free slicing and allocation-free parsing with Span<T>, a measured allocation difference, stackalloc and its safe pattern, ref struct restrictions, and Memory<T> for async code.
Expression Trees in C#: Holding a Lambda as Data, and the Bridge to EF Core
The difference between Func and Expression<Func>, looking at the tree's nodes and Compile, building a dynamic filter with Expression factory methods, a small SQL translator with ExpressionVisitor, IQueryable and EF Core 6's ToQueryString output, a captured variable turning into a parameter, the untranslatable method error, limits such as CS0834, CS8072 and CS8110, and the 70-microsecond cost of Compile measured with BenchmarkDotNet.