[Proposal]: Final initializers
- Dominant language
- C#
- Stars
- 12.7k
- Forks
- 1.1k
- Avg merge
- 11h 1m
- Merged PRs (30d)
- 3
Description
# Final initializers
* Specification: [proposals/final-initializers.md](https://github.com/dotnet/csharplang/blob/main/proposals/final-initializers.md)
* Discussion: https://github.com/dotnet/csharplang/discussions/6591
## Summary
Final initializers are a proposed new kind of member declaration that runs at the end of an object's initialization—after constructors, object and collection initializers, and `with` expressions.
Early notes refer to these as "validators."
```cs
public class Range
{
public int Min { get; init; }
public int Max { get; init; }
init
{
if (Max < Min)
{
throw new InvalidOperationException("Max must not be less than min.");
}
}
}
```
## Design meetings
[2020-04-27: Initial decision on `init {`...`}` syntax](https://github.com/dotnet/csharplang/blob/main/meetings/2020/LDM-2020-04-27.md#primary-constructor-bodies-and-validators)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.