Skip to content

Declare immutable structs as readonly – readonly struct rules lack _init-only_ setter option #27199

@deep-outcome

Description

@deep-outcome

All properties must be read-only, including auto-implemented properties.

C# 9.0 init-only setter option is not mentioned here.

From readonly struct

All data members of a readonly struct must be read-only as follows:

  • Any field declaration must have the readonly modifier
  • Any property, including auto-implemented ones, must be read-only. In C# 9.0 and later, a property may have an init accessor.

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.


Associated WorkItem - 54747

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.advanced-concepts/subsvcdotnet-csharp/svcokr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions