▲ | twodave a day ago | |
There's a draft spec out there for discrete unions in C# fwiw. I wouldn't be surprised to see it in another version or two. And while I agree that I don't love some of the object initialization patterns C# allows--I respect that other people might have different style than me and don't mind ignoring that those styles exist when writing my own stuff :) My general rule goes something like: 1. Use record types for any simple data structure 2. Avoid using primary constructors (even on record types). 3. Use { get; init; } properties for everything unless there's a good reason not to. 4. For things that need to carry internal state, have different methods for mutations, emit events, etc., use a class with regular old constructors and either { get; } (for immutable) or { get; private set; } (mutable) properties as needed. |