C#C
C#3y ago
Vir Godem

❔ Record help

I've noticed this code doesn't raise any errors:

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?
Was this page helpful?