iMasters.com - Knowledge for Developers.
Follow Us
Home Backend What’s New in C# 11 lowercase class name warnings
Backend

What’s New in C# 11 lowercase class name warnings

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.

Written by
Renato Groffe

Worked as a consultant in systems development activities for over 15 years. Microsoft MVP (Most Valuable Professional) and MTAC (Multi-Plataform Technical Audience Contributor) program participant. Bachelor in Information Systems, specialization in Software Engineering, and MBA in Business Intelligence. He is also a lecturer and technical author on portals and specialized magazines, focusing on Microsoft technologies and good practices in the software area.

Leave a comment

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Related Articles

Backend

How to Create a Skill for Amazon’s Virtual Assistant Alexa

If you didn’t know, it is not necessary for an Amazon Echo...

Backend

The APIs role in a 5G world

5G is about to revolutionize how we connect and use technology daily....

Backend

EF Core using AsNoTracking with Identity Resolution

Today we will see the consequences of using AsNoTracking with the Identity...

Backend

Understand key features added in ASP.NET Core 7.0

Version 7.0 of the .NET platform brought many new features in this...