Skip to content

Document sizeof behavior on enum types#54560

Open
heissenberg06 wants to merge 2 commits into
dotnet:mainfrom
heissenberg06:sizeof-enum-docs
Open

Document sizeof behavior on enum types#54560
heissenberg06 wants to merge 2 commits into
dotnet:mainfrom
heissenberg06:sizeof-enum-docs

Conversation

@heissenberg06

@heissenberg06 heissenberg06 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #54499

Adds a bullet to the sizeof operator reference noting that sizeof applied to an enum type returns the size of its underlying integral type, that the size is evaluated at compile time, and that changing the underlying type of an enum in a referenced assembly requires recompiling consuming code to observe the new size.


Internal previews

📄 File 🔗 Preview link
docs/csharp/language-reference/operators/sizeof.md sizeof operator - determine the memory needs for a given type

@heissenberg06 heissenberg06 requested review from a team and BillWagner as code owners June 28, 2026 22:31
@dotnetrepoman dotnetrepoman Bot added this to the June 2026 milestone Jun 28, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates PR is created by someone from the .NET community. label Jun 28, 2026
@GeeLaw

GeeLaw commented Jun 28, 2026

Copy link
Copy Markdown

The opening paragraph should also mention sizeof on enum types need not appear in unsafe.

@heissenberg06

Copy link
Copy Markdown
Contributor Author

The opening paragraph should also mention sizeof on enum types need not appear in unsafe.

Good catch, thanks. Updated the opening paragraph to note that sizeof on an enumeration type is allowed in safe code (its size is a compile-time constant) and doesn't require an unsafe context. Also moved the enum link to the first mention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sizeof on enum types

2 participants