Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Guard Helpers, Equality Helpers and What Arrived in the BCL from .NET 8 to 11
ArgumentNullException.ThrowIfNull and the ArgumentOutOfRangeException helpers of .NET 8 use CallerArgumentExpression to put the parameter name, the value and the rule into the exception in a single line. We convert Bookstore's Order constructor to these helpers and show custom guard methods, the multi-targeting trap, HashCode.Combine and keys that change, choosing StringComparer and EqualityComparer<T>.Create, how Lazy<T> caches exceptions, and a table of the BCL APIs added from .NET 8 to 11.
Equality and Comparison in C#: Equals, GetHashCode, IEquatable and IComparable
Reference and value equality, the Equals and GetHashCode contract, IEquatable<T> and the == operator, equality in structs, sorting with IComparable<T>, and comparers that decide from the outside.