Small things we got wrong in .NET
summary
Claims and gotchas with concrete examples: value types land on stack or heap depending on context, not always stack; var is compile time, dynamic is runtime; List<T> uses an underlying array with default capacity 4; Any() beats Count on enumerables unless you can read a Count property; overloaded == can lie so use is null; string.Empty and "" end up identical at runtime; StringBuilder is slower for small joins; Environment.FailFast skips finally; RegexOptions.Compiled can be 200× slower if compiled per call; Count(predicate) differs from Where().Count() by about 5×.
AI-written summary · about








