Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/csharp/language-reference/operators/sizeof.md
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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).

[!INCLUDE[csharp-version-note](../includes/initial-version.md)]

Expand Down Expand Up @@ -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 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:
Expand Down
Loading