Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The article on Object and Collection Initializers should mention and explain benefits of init and required. #35014

Closed
konrad-jamrozik opened this issue Apr 15, 2023 · 1 comment · Fixed by #36232
Labels
dotnet-csharp/svc fundamentals/subsvc help wanted Good for community contributors to help [up-for-grabs]

Comments

@konrad-jamrozik
Copy link
Contributor

konrad-jamrozik commented Apr 15, 2023

I believe the article on Object and Collection Initializers should mention the init accessor as well as required 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:

  • like a ctor param, but also enabling usage of object initializers;
  • another take: like a set accessor, but only during construction/init time, thus preventing mutability post-creation.

requried:

  • like 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.

@BillWagner
Copy link
Member

Thanks @konrad-jamrozik

That's a great suggestion. I've added it to our backlog for when we update this article. I've also added the "help wanted" label in case anyone wants to submit a PR in the interim.

@BillWagner BillWagner added the help wanted Good for community contributors to help [up-for-grabs] label Apr 17, 2023
@ghost ghost added in-pr This issue will be closed (fixed) by an active pull request. and removed in-pr This issue will be closed (fixed) by an active pull request. labels Jul 12, 2023
@ghost ghost removed the in-pr This issue will be closed (fixed) by an active pull request. label Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-csharp/svc fundamentals/subsvc help wanted Good for community contributors to help [up-for-grabs]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants