Vir Godem
How do collections implement Remove and Contains?
In particular, in the case of records. Do they look for exact references, or do they apply the record equality test as I'd expect them to?
Let's say I've got a simple record like:
And I've got a collection of
S
, such as a HashSet
. Will the HashSet test the values of X
and Y
and return true if it finds that the HashSet contains such an element? Or will it need the exact reference to S
?
That is, would the following be enough to find a reference containing an S
instance with X = 5
and Y = "42"
?
5 replies
❔ Record help
I've noticed this code doesn't raise any errors:
Tbh, I tried this because I needed something similar. That is, many of my properties for a class will need B as input for their properties. However, I also want B to be mutable. So I was hoping to achieve that by doing something like the above.
I don't see anything like this in the MS Learn documentation on records, so I'm wondering if this case was glossed over or missed, or it should compile properly. And if it does, should I expect property B to be mutable (like I want) or not?
14 replies