The article on Object and Collection Initializers
should mention and explain benefits of init
and required
.
#35014
Labels
dotnet-csharp/svc
fundamentals/subsvc
help wanted
Good for community contributors to help [up-for-grabs]
I believe the article on
Object and Collection Initializers
should mention theinit
accessor as well asrequired
modifier.Specifically, it should be explained how these keywords enable advanced control over initializations, similar to how this section on
Object Initializers with collection read-only property initialization
does.In brief:
init
:set
accessor, but only during construction/init time, thus preventing mutability post-creation.requried
:init
, but also must be set in object initializer, thus preventing only partially constructed objects (and precludes usage in ctor unless[SetsRequiredMembers]
is used).Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: