From af34dd78ba0d5bc9fd8dab85c94a51849af4c3fa Mon Sep 17 00:00:00 2001 From: heissenberg06 <145454044+heissenberg06@users.noreply.github.com> Date: Mon, 29 Jun 2026 01:28:11 +0300 Subject: [PATCH 1/3] Document sizeof behavior on enum types --- docs/csharp/language-reference/operators/sizeof.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/operators/sizeof.md b/docs/csharp/language-reference/operators/sizeof.md index 159618d9bb89e..6d0a0e0533969 100644 --- a/docs/csharp/language-reference/operators/sizeof.md +++ b/docs/csharp/language-reference/operators/sizeof.md @@ -1,7 +1,7 @@ --- title: "sizeof operator - determine the storage needs for a type" description: "Learn about the C# `sizeof` operator that returns the memory amount occupied by a variable of a given type." -ms.date: 06/16/2026 +ms.date: 06/29/2026 f1_keywords: - "sizeof_CSharpKeyword" - "sizeof" @@ -41,6 +41,7 @@ In [unsafe](../keywords/unsafe.md) code, you can use `sizeof` on any non-`void` - The size of a reference or pointer type is the size of a reference or pointer, not the size of the object it might refer to. - The size of a value type, unmanaged or not, is the size of such a value. +- The size of an [enumeration type](../builtin-types/enum.md) is the size of its underlying integral type. This size is a compile-time constant. If the underlying type of an enum defined in a referenced assembly later changes, code that applied `sizeof` to that enum must be recompiled to observe the new size. - The size of a `ref struct` type is the size of the value. The size of every `ref` field is the size of a reference or pointer, not the size of the value it refers to. The following example demonstrates the usage of the `sizeof` operator: From 496bdcf1d64a8049d85585b7d22116043f4ce0b7 Mon Sep 17 00:00:00 2001 From: heissenberg06 <145454044+heissenberg06@users.noreply.github.com> Date: Mon, 29 Jun 2026 12:09:46 +0300 Subject: [PATCH 2/3] Clarify that sizeof on enum types doesn't require unsafe context --- docs/csharp/language-reference/operators/sizeof.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/operators/sizeof.md b/docs/csharp/language-reference/operators/sizeof.md index 6d0a0e0533969..a863380268331 100644 --- a/docs/csharp/language-reference/operators/sizeof.md +++ b/docs/csharp/language-reference/operators/sizeof.md @@ -10,7 +10,7 @@ helpviewer_keywords: --- # sizeof operator - determine the memory needs for a given type -The `sizeof` operator returns the number of bytes occupied by a variable of a given type. In safe code, the argument to the `sizeof` operator must be the name of a built-in [unmanaged type](../builtin-types/unmanaged-types.md) whose size isn't platform-dependent. +The `sizeof` operator returns the number of bytes occupied by a variable of a given type. In safe code, the argument to the `sizeof` operator must be the name of a built-in [unmanaged type](../builtin-types/unmanaged-types.md) whose size isn't platform-dependent, or an [enumeration type](../builtin-types/enum.md). The size of these types is a compile-time constant, so `sizeof` doesn't require an unsafe context. [!INCLUDE[csharp-version-note](../includes/initial-version.md)] @@ -41,7 +41,7 @@ In [unsafe](../keywords/unsafe.md) code, you can use `sizeof` on any non-`void` - The size of a reference or pointer type is the size of a reference or pointer, not the size of the object it might refer to. - The size of a value type, unmanaged or not, is the size of such a value. -- The size of an [enumeration type](../builtin-types/enum.md) is the size of its underlying integral type. This size is a compile-time constant. If the underlying type of an enum defined in a referenced assembly later changes, code that applied `sizeof` to that enum must be recompiled to observe the new size. +- The size of an enumeration type is the size of its underlying integral type. This size is a compile-time constant. If the underlying type of an enum defined in a referenced assembly later changes, code that applied `sizeof` to that enum must be recompiled to observe the new size. - The size of a `ref struct` type is the size of the value. The size of every `ref` field is the size of a reference or pointer, not the size of the value it refers to. The following example demonstrates the usage of the `sizeof` operator: From ec3c1df8e9134643fa0a63c94248cf932eef4038 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Tue, 30 Jun 2026 09:30:57 -0400 Subject: [PATCH 3/3] Update docs/csharp/language-reference/operators/sizeof.md --- docs/csharp/language-reference/operators/sizeof.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/operators/sizeof.md b/docs/csharp/language-reference/operators/sizeof.md index a863380268331..cc786c042fdec 100644 --- a/docs/csharp/language-reference/operators/sizeof.md +++ b/docs/csharp/language-reference/operators/sizeof.md @@ -10,7 +10,7 @@ helpviewer_keywords: --- # sizeof operator - determine the memory needs for a given type -The `sizeof` operator returns the number of bytes occupied by a variable of a given type. In safe code, the argument to the `sizeof` operator must be the name of a built-in [unmanaged type](../builtin-types/unmanaged-types.md) whose size isn't platform-dependent, or an [enumeration type](../builtin-types/enum.md). The size of these types is a compile-time constant, so `sizeof` doesn't require an unsafe context. +The `sizeof` operator returns the number of bytes occupied by a variable of a given type. In safe code, the argument to the `sizeof` operator must be the name of a built-in [unmanaged type](../builtin-types/unmanaged-types.md) whose size isn't platform-dependent, or an [enumeration type](../builtin-types/enum.md). [!INCLUDE[csharp-version-note](../includes/initial-version.md)]