3 ms·
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-with-expressio
by benmmurphy 1y ago
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-with-expressions-and-calculated-properties/ https://blog.codingmilitia.com/2022/09/01/beware-of-records-...
- firesteelrain 1y ago> 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.
- bee_rider 1y agoDid you go through the same journey as the author of the article, in compressed form? Further evidence it is a confusing feature, if so!
- firesteelrain 1y agoYes! 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