Identifiers should not match keywords
Identifiers should not match keywords
Microsoft docsDescription
Identifiers for namespaces, types, and virtual and interface members should not match keywords that are defined by languages that target the common language runtime. Depending on the language that is used and the keyword, compiler errors and ambiguities can make the library difficult to use.
This rule checks against keywords in the following languages:
- Visual Basic
- C#
- C++/CLI
Case-insensitive comparison is used for Visual Basic keywords, and case-sensitive comparison is used for the other languages.
Cause
The name of a namespace, type, or virtual or interface member matches a reserved keyword in a programming language.
By default, this rule only looks at externally visible namespaces, types, and members, but you can configure visibility and symbol kinds.
How to fix violations
Select a name that does not appear in the list of keywords.
Example
#pragma warning disable CA1716
// The code that's violating the rule is on this line.
#pragma warning restore CA1716When to suppress
You can suppress a warning from this rule if you're sure that the identifier won't confuse users of the API, and that the library is usable in all available languages in .NET.