Mastering Records
TechGuys
0:00 / 0:00
Mastering Records
19 просмотров · 4 дня назад
TechGuys
11 подписчиков
19 просмотров · 4 дня назад
Records exist to fix one specific problem: plain classes use reference equality by default, and writing value equality by hand means overriding Equals, GetHashCode, ToString, and the equality operators every single time. In this chapter, we look at exactly what the compiler generates for a record — verified directly against the real decompiled output, not just described — where that convenience genuinely breaks down (mutable records, and equality that doesn't reach into collections), and why the default equality on an ordinary struct is correct but slow. We close with a real BenchmarkDotNet run comparing default struct equality against record struct, proving the reflection cost is real and measurable.
What we cover:
What a hand-written value equality override actually costs you
record vs. plain class: the same default behavior gap from the value types chapter
What the compiler actually generates for a record, viewed directly via SharpLab
Where records break: mutable properties, and equality that doesn't recurse into collections
Why default struct equality uses reflection, and how record struct avoids it — benchmarked
Every claim in this video is backed by real, live-run output — no hand-waved numbers.
#csharp #dotnet #programming #softwareengineering #csharpperformance #dotnetinternals #benchmarkdotnet #records #jetbrainsrider