init accessor

A property accessor written init instead of set, which allows the value to be assigned only while the object is being created.

In more detail

An object initialiser can set it once; nothing can change it afterwards, which makes the property effectively immutable. Records use init accessors for their positional properties.

Example

public Guid Id { get; init; } = Guid.NewGuid();

Related terms

Taught in

References