From 19fccf8b86311524a56cfa9ef771ca81041289b9 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 14 Nov 2023 23:00:53 +0800 Subject: [PATCH 1/2] Tweak constants programming guide --- .../csharp/programming-guide/classes-and-structs/constants.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/programming-guide/classes-and-structs/constants.md b/docs/csharp/programming-guide/classes-and-structs/constants.md index a05c240482e3c..26b7ea9609de4 100644 --- a/docs/csharp/programming-guide/classes-and-structs/constants.md +++ b/docs/csharp/programming-guide/classes-and-structs/constants.md @@ -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 ) 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`. Built-in reference types other than 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. From 424d2e8c463d71601144dc44f19af705f4ab89c9 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Tue, 14 Nov 2023 23:27:54 +0800 Subject: [PATCH 2/2] Be explicit about the reference type being constant Co-authored-by: Bill Wagner --- docs/csharp/programming-guide/classes-and-structs/constants.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/programming-guide/classes-and-structs/constants.md b/docs/csharp/programming-guide/classes-and-structs/constants.md index 26b7ea9609de4..25f0d8aaa6cbe 100644 --- a/docs/csharp/programming-guide/classes-and-structs/constants.md +++ b/docs/csharp/programming-guide/classes-and-structs/constants.md @@ -9,7 +9,7 @@ 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) may be declared as `const`. Built-in reference types other than 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. +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 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.