Skip to content

Commit b0508a2

Browse files
Tweak constants programming guide (dotnet#38055)
* Tweak constants programming guide * Be explicit about the reference type being constant Co-authored-by: Bill Wagner <[email protected]> --------- Co-authored-by: Bill Wagner <[email protected]>
1 parent b1838f6 commit b0508a2

File tree

1 file changed

+2
-2
lines changed
  • docs/csharp/programming-guide/classes-and-structs

1 file changed

+2
-2
lines changed

docs/csharp/programming-guide/classes-and-structs/constants.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
title: "Constants - C# Programming Guide"
33
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.
44
ms.date: 07/20/2015
5-
helpviewer_keywords:
5+
helpviewer_keywords:
66
- "C# language, constants"
77
- "constants [C#]"
88
ms.assetid: 1fb39621-1738-49b1-a1b3-8587f109123f
99
---
1010
# Constants (C# Programming Guide)
1111

12-
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.
12+
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.
1313

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

0 commit comments

Comments
 (0)