-
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
Arrays that contain reference types #21941
Comments
That's a great suggestion @matt-rule I'll answer what I can briefly here, and we'll add this article to our next set of updates on null safety.
There isn't a good alternative. Perf is one reason: all those objects would need to be allocated. All those constructors would need to run. It would also require an accessible default constructor.
Partially the first answer: there isn't a good way to fix that warning.
These are harder. The short version is to avoid the visibility of the array before objects in the array are allocated or initialized. I know those answers are incomplete. I hope that helps you get started while we address this with a new article. |
Thank you very much Bill! I know this is off-topic but coincidentally yesterday I bought your book "More Effective C#" from Amazon. Looking forward to a good read! |
Fixes dotnet#21941: Add description of the default values for arrays of reference types. Fixes dotnet#30348: Edit pass Fixes dotnet#33667: Update the description of the nullable context to match the language used in the C# 8 draft standard Fixes dotnet#36767: Add language on declaring a non-null array of nullable reference types and a nullable array of non-nullable reference types. Also, perform a general edit pass.
I Google searched for "arrays of nullable reference types c#" because there are some interesting design decisions in this area of .NET. I found this very informative article on the pitfalls of using nullable reference types. One of these pitfalls is arrays of non-nullable references. While the article is informative in general, there is only a paragraph of information about this particular topic and I feel like there could be more info because I'm currently working with these in my project and trying to work out what options there are.
My request isn't in the exact format you asked for, because I'm not asking for a whole article to be written on this. It would be nice to see a paragraph or two added to the existing article, discussing:
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Associated WorkItem - 350756
The text was updated successfully, but these errors were encountered: