Skip to content

[Proposal]: Final initializers #10033

@jnm2

Description

@jnm2

Final initializers

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."

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

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions