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
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
title: "Constants - C# Programming Guide"
description: Constants in C# are compile-time literal values, which do not change once the program is compiled. Only C# built-in types can be constants.
ms.date: 07/20/2015
helpviewer_keywords:
helpviewer_keywords:
- "C# language, constants"
- "constants [C#]"
ms.assetid: 1fb39621-1738-49b1-a1b3-8587f109123f
---
# Constants (C# Programming Guide)

Constants are immutable values which are known at compile time and do not change for the life of the program. Constants are declared with the [const](../../language-reference/keywords/const.md) modifier. Only the C# [built-in types](../../language-reference/builtin-types/built-in-types.md) (excluding <xref:System.Object?displayProperty=nameWithType>) may be declared as `const`. User-defined types, including classes, structs, and arrays, cannot be `const`. Use the [readonly](../../language-reference/keywords/readonly.md) modifier to create a class, struct, or array that is initialized one time at run time (for example in a constructor) and thereafter cannot be changed.
Constants are immutable values which are known at compile time and do not change for the life of the program. Constants are declared with the [const](../../language-reference/keywords/const.md) modifier. Only the C# [built-in types](../../language-reference/builtin-types/built-in-types.md) may be declared as `const`. Reference type constants other than <xref:System.String> can only be initialized with a [null](../../language-reference/keywords/null.md) value. User-defined types, including classes, structs, and arrays, cannot be `const`. Use the [readonly](../../language-reference/keywords/readonly.md) modifier to create a class, struct, or array that is initialized one time at run time (for example in a constructor) and thereafter cannot be changed.

C# does not support `const` methods, properties, or events.

Expand Down