Vir Godem
Vir Godem
CC#
Created by Vir Godem on 10/3/2024 in #help
WPF Submenu Styling
No description
7 replies
CC#
Created by Vir Godem on 3/22/2023 in #help
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:
record S(int X, string Y);
record S(int X, string Y);
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"?
return HashSet.Contains(new S(5, "42"));
return HashSet.Contains(new S(5, "42"));
5 replies
CC#
Created by Vir Godem on 2/26/2023 in #help
❔ Record help
I've noticed this code doesn't raise any errors:
public record A(int B)
{
public required int B { get; set; }
}
public record A(int B)
{
public required int B { get; set; }
}
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