dotnet / dotnet/csharplang

[Proposal]: Final initializers

Open
#10,033 0 comments 0 reactions 1 assignee Claimed by @jnm2 View on GitHub
Proposal champion
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.