C# PROGRAMMING
Init accessor C# 9.0
This article demonstrates how new feature init property works.
Published in
1 min readAug 9, 2020
Firstly, the problem with getter/setter property is that properties are mutable, which means the type of object can be modified after its creation.
Init accessor is a variant of set accessor which addresses the above problem with properties.
There are two variants with init accessor
Init Accessor without read-only
The below example shows how to create an init accessor. Hence the property becomes immutable but can be assigned once during object initialization, but further changes in value result in an exception.