Skip to content

Commit cfd62a4

Browse files
Constant definition update for issue 41677 (dotnet#41726)
* Fix for 41687 * Additional work for fixing 41687, adjust for other mentions of double quotations * Fix for issue 41677, adds better definition for constants * Update docs/csharp/language-reference/preprocessor-directives.md Co-authored-by: Bill Wagner <[email protected]> --------- Co-authored-by: Bill Wagner <[email protected]>
1 parent b3c58e1 commit cfd62a4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/csharp/language-reference/preprocessor-directives.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ You use `#define` to define a symbol. When you use the symbol as the expression
184184
```
185185

186186
> [!NOTE]
187-
> The `#define` directive cannot be used to declare constant values as is typically done in C and C++. Constants in C# are best defined as static members of a class or struct. If you have several such constants, consider creating a separate "Constants" class to hold them.
187+
> In C#, primitive constants should be defined using the [`const`](keywords/const.md) keyword. A `const` declaration creates a `static` member that can't be modified at runtime. The `#define` directive can't be used to declare constant values as is typically done in C and C++. If you have several such constants, consider creating a separate "Constants" class to hold them.
188188
189189
Symbols can be used to specify conditions for compilation. You can test for the symbol with either `#if` or `#elif`. You can also use the <xref:System.Diagnostics.ConditionalAttribute> to perform conditional compilation. You can define a symbol, but you can't assign a value to a symbol. The `#define` directive must appear in the file before you use any instructions that aren't also preprocessor directives. You can also define a symbol with the [**DefineConstants**](compiler-options/language.md#defineconstants) compiler option. You can undefine a symbol with `#undef`.
190190

0 commit comments

Comments
 (0)