C# PROGRAMMING

Init accessor C# 9.0

This article demonstrates how new feature init property works.

Sukhpinder Singh
C# Programming
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.

Init Accessor with read-only

--

--

Sukhpinder Singh
C# Programming

Programmer by heart | C# | .Net 6 | .Net 8 | dotnet | dotnetcore | Kubernetes | Angular | AWS | Remember to 👏 Linktree: https://linktr.ee/sukhpindersingh