Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Events in C#: EventHandler, Safe Raising and Subscription Leaks
How the event keyword protects a delegate and CS0070, the private field and add/remove methods the compiler generates, the EventHandler convention and records as event data, safe raising with ?.Invoke, custom add/remove accessors and CS0079, a 50 MB subscription leak measured with WeakReference, and a Subscribe method that returns IDisposable.
Lambdas and Closures in C#: The Captured Variable Trap
Lambda shapes and the C# 10 explicit return type, a closure capturing the variable rather than its value, seeing the compiler-generated display class with reflection, the captured for loop variable and the C# 5 foreach change, measuring 88 bytes of allocation per closure, static lambdas and CS8820, and the capture bug that meets deferred LINQ.
Delegates, Func and Action in C#: Passing Methods Around as Values
A delegate is a type that holds a method: a class deriving from MulticastDelegate, Method and Target, Func/Action/Predicate, the natural type of lambdas in C# 10 and CS8917, passing methods as parameters, the last result of a multicast delegate and the broken chain, converting between delegate types and variance, and the traps of null delegates and lambdas that -= won't remove.