-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Missing docs and example on object initializer that lacks a new
keyword
#12979
Comments
Thanks for writing this up @AArnott I’ve added it to our backlog to update when we next update this topic. |
This issue has been closed as part of the issue backlog grooming process outlined in #22351. That automated process may have closed some issues that should be addressed. If you think this is one of them, reopen it with a comment explaining why. Tag the |
This feature is a gem in the C# language that really should be made known, and otherwise isn't documented anywhere that I can find. |
I was losing my mind over this until I found this issue. ReSharper suggested I'd do this in a code I was writing and I thought to myself: I have never seen this before, is this new? I couldn't figure out how I've never seen this with more than 10 years working with C# and just couldn't understand what was this, specially when I read through the object initializer docs and didn't find any mention to this either. Is this being worked on? |
After discovering this worked in Rider I spent well over an hour Googling and re-reading the documentation trying to figure out why it worked and where it was documented. |
From C# ecma spec 12.7.11.3 it is possible to initialize values into a member using a
= { }
syntax (note the lack of thenew
keyword). By this it's possible to initialize a new object deeply within its properties that may not even make a setter available. This is very interesting and useful, and should be documented here.Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: