3 ms·
C# records default to immutability. However, struct records being a lower level construct default to mutable (which can be changed with readonly keyword):
by neonsunset 3y ago
C# records default to immutability. However, struct records being a lower level construct default to mutable (which can be changed with readonly keyword):
record User(string Name, DateOnly DoB); // immutable
record struct Cursor(int X, int Y); // mutable
readonly record struct Point(int X, int Y); // immutable