C# keywords are special identifiers from the point of view of the C# compiler and are normally associated with basic implementations such as structure declarations, conditional branches, and value manipulation. A feature common to all keywords is the fact that they are always written in lowercase, and it should be noted that instructions in C# are case-sensitive by default.
A complete list of currently anticipated keywords for C# can be found at the following link:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
As these are reserved use elements, we cannot use keywords in the names of classes, methods, variables, and other constructions. And C# 11 now goes even further, generating build/build alerts for classes whose names are all lowercase characters. This new capability was named Warning Wave 7, a type of alert identified by the CS8981 code and whose use I recently demonstrated live on the .NET Channel (which can be watched for free on YouTube and includes other features of C# 11):
The purpose of this new feature is to prevent class names from conflicting with likely new keywords, assuming that the latter will always be made up of lowercase characters. As an example, we can take the test, assert, and validator classes presented in the following listing:
Even with their names formed only by lowercase letters, these types can be used normally in a .NET application. This is shown by the next listing:
The execution result of which is shown in the following image:
The alerts produced can be viewed from within Visual Studio 2022:
Or even during the process of compiling a project via .NET CLI, as in the following example using Windows Terminal:
This example is also available on GitHub:
https://github.com/renatogroffe/CSharp11-WarningWave7
*The content of this article is the author’s responsibility and does not necessarily reflect the opinion of iMasters.
Leave a comment