-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow parameterless constructors in record structs #52240
Comments
Hi - is this in .NET 6 preview 6? It'd be great if a user could specify a validation method so that the struct could never be created with an invalid value, e.g. public record struct Age(int Value)
{
public Age()
{
if(Value < 0) throw new InvalidOperationException("Ages cannot be negative");
}
} |
No, it barely missed .NET 6 preview 7. It'll be in the following preview. |
I'm ideally looking for the succinctness of records, the memory traits of value-type primitives, and constraits that mean no invalid instances can be created. https://dunnhq.com/posts/2021/primitive-obsession/ |
Update: it did make it into .NET 6 preview 7 after all (and VS 2022 preview 3). |
[This issue is referenced in source]
When the "record structs" feature gets merged with the "parameterless struct constructor" feature, we may need to make some adjustments to record structs.
Some scenarios are interesting:
The text was updated successfully, but these errors were encountered: