Struct initialization and default values – this
access
#42332
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
Type of issue
Typo
Description
From https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/struct#struct-initialization-and-default-values
This is unclear. One can obtain struct by
new
ordefault
. 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
The text was updated successfully, but these errors were encountered: