Re:Unexpected inconsistency in records – Jon Skeet's coding ...
by benmmurphy on Tuesday July 22, 2025 @09:32AM
(#44646672)
Seems like enough of a gotcha that other people have stumbled upon the issue as well: https://blog.codingmilitia.com/2022/09/01/beware-of-records-...
[ Parent
| on HN ]
Re:Unexpected inconsistency in records – Jon Skeet's coding ...
by firesteelrain on Tuesday July 22, 2025 @09:51AM
(#44646906)
> SomeCalculatedValue in the second line still has the same value as in the first. This makes sense, as what happens when we use the with expression, is that the record is cloned and then the properties provided within the brackets are overwritten.
Shouldn't SomeCalculatedValue be "This is another some value *calculated*" when using with ?
Edit: Actually that is the problem, that it isn't "recalculating" due to the way that the initialization of read-only properties works in a C# record.
Re:Unexpected inconsistency in records – Jon Skeet's coding ...
by bee_rider on Tuesday July 22, 2025 @11:19AM
(#44648150)
Did you go through the same journey as the author of the article, in compressed form? Further evidence it is a confusing feature, if so!
Re:Unexpected inconsistency in records – Jon Skeet's coding ...
by firesteelrain on Tuesday July 22, 2025 @11:52AM
(#44648746)
Yes! It didn’t make sense at first. It’s not intuitive unless you understand the internals on how it works and then it makes sense. I don’t think there is anything wrong just needs to be documented better