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

Struct initialization and default values – this access #42332

Open
bravequickcleverfibreyarn opened this issue Aug 26, 2024 · 0 comments · May be fixed by #43694
Open

Struct initialization and default values – this access #42332

bravequickcleverfibreyarn opened this issue Aug 26, 2024 · 0 comments · May be fixed by #43694
Assignees
Labels
doc-enhancement Improve the current content [org][type][category] dotnet-csharp/svc in-pr This issue will be closed (fixed) by an active pull request. lang-reference/subsvc Pri1 High priority, do before Pri2 and Pri3

Comments

@bravequickcleverfibreyarn
Copy link
Contributor

Type of issue

Typo

Description

From https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/struct#struct-initialization-and-default-values

If this is accessed before all fields are assigned, the struct is initialized to the default value before the constructor body executes.

This is unclear. One can obtain struct by new or default. Trying to use only declared struct results in Compiler Error CS0170.

So if accessing: default struct, all fields are 0-bit patterned; new struct, all fields are set by ctor body. In either case all fields have some "good" value. Also expecting some ctor run after sole initialization implies using different struct second time.

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/struct#struct-initialization-and-default-values

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/builtin-types/struct.md

Document Version Independent Id

0960802e-80c3-cb56-cb8b-ab1f1b20fb4e

Article author

@BillWagner

Metadata

  • ID: d9220116-e950-04cf-b6d5-70d15a084a22
  • Service: dotnet-csharp
  • Sub-service: lang-reference
@issues-automation issues-automation bot added dotnet-csharp/svc lang-reference/subsvc Pri1 High priority, do before Pri2 and Pri3 labels Aug 26, 2024
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Aug 26, 2024
@BillWagner BillWagner added the doc-enhancement Improve the current content [org][type][category] label Aug 26, 2024
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label Aug 26, 2024
@BillWagner BillWagner self-assigned this Nov 22, 2024
@dotnetrepoman dotnetrepoman bot added 🗺️ mapQUEST Only used as a way to mark an issue as updated for quest. RepoMan should instantly remove it. and removed 🗺️ mapQUEST Only used as a way to mark an issue as updated for quest. RepoMan should instantly remove it. labels Nov 22, 2024
@BillWagner BillWagner linked a pull request Nov 22, 2024 that will close this issue
@dotnet-policy-service dotnet-policy-service bot added the in-pr This issue will be closed (fixed) by an active pull request. label Nov 22, 2024
@dotnetrepoman dotnetrepoman bot added 🗺️ mapQUEST Only used as a way to mark an issue as updated for quest. RepoMan should instantly remove it. and removed 🗺️ mapQUEST Only used as a way to mark an issue as updated for quest. RepoMan should instantly remove it. labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-enhancement Improve the current content [org][type][category] dotnet-csharp/svc in-pr This issue will be closed (fixed) by an active pull request. lang-reference/subsvc Pri1 High priority, do before Pri2 and Pri3
Projects
Status: 👀 In review
Development

Successfully merging a pull request may close this issue.

3 participants