Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
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.
Generic Classes, Generic Methods and Constraints in C#
Writing your own generic classes and methods: paging with Page<T>, the limits of type inference, default and the unconstrained T? trap. The class, struct, new(), notnull, unmanaged and Enum constraints with real compiler errors; per-closed-type statics and the == trap in generic code.
Why C# Has Generics: ArrayList, Boxing and Type Safety
The price of ArrayList storing everything as object: InvalidCastException pushed to run time, boxing of value types and eight times the memory. Type safety with List<T>, how the runtime sees generic types, and bringing old collections into the generic world with OfType and Cast.