Skip to main content
An init-only property is a property that restricts assignment to the phase of object construction. By replacing the standard set accessor with the init keyword, the C# compiler enforces immutability for that property once the initialization phase completes.

The Initialization Phase

The C# compiler defines a strict window during which an init accessor can be invoked. Assignment is exclusively permitted in the following contexts:
  1. Object Initializers: During the instantiation of the object using curly brace syntax.
  2. Constructors: Within the constructor of the declaring type or a derived type.
  3. Inline Initializers: At the point of property declaration.
  4. with Expressions: During non-destructive mutation to create a new instance.
  5. Other init Accessors: Within the body of another init accessor on the same instance.
Once the execution context leaves these boundaries, the property becomes strictly read-only. Attempting to assign a value to an init property outside this phase results in compiler error CS8852.

Explicit Implementation and Readonly Backing Fields

When manually implementing an init accessor rather than using an auto-implemented property, the accessor is granted special compiler privileges to mutate readonly backing fields. This mirrors the behavior of a constructor.

Interaction with with Expressions

Init-only properties are foundational to non-destructive mutation in C#. When a with expression is evaluated, the compiler creates a clone of the original object and then executes the init accessors for the properties specified in the initializer block.

Type Compatibility

The init accessor is a feature of the property system itself, not tied to a specific type category. It is fully supported across:
  • class
  • struct
  • record (Positional properties are compiled as get; init; for record class and readonly record struct. However, positional properties in a standard record struct are compiled as get; set;)
  • interface (Interfaces can declare init accessors to enforce initialization contracts on implementing types)
Tired of Poor C# Skills? Fix That With Deep Grasping!Learn More