Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News C# Warning Waves Hint at New Keywords in the Future

C# Warning Waves Hint at New Keywords in the Future

This item in japanese

Like C# 9 and 10, C# 11 has quietly added a new compiler warning. This opt-in warning prevents the use of type names (e.g. classes, structs, and interfaces) that are all lowercase.

This warning was created so Microsoft can more easily add new keywords in the future. Since C# keywords always consist of entirely lowercase ASCII letters, putting in any other letter will prevent the type name from ever clashing with a future keyword.

The warning's documentation doesn’t go into detail about what keywords are being considered.


The C# toolchain has always divided its messages into three broad types: compiler errors, compiler warnings, and static analysis warnings. Errors are show stoppers that prevent the compiler from completing its work. When these occur, the compiler is basically saying the problem it detected can’t be ignored.

The next class is compiler warnings. These imply that a significant problem exists, but the compiler can still produce an output file. They are enabled by default, but can be ignored by the developer. Alternately, a developer can request they be treated like errors.

The final type is essentially "everything else". Static analysis errors may only be a problem for certain types of applications, or even for certain parts of an application. They are far more prone to more false positives, that is to say inappropriate warnings, than compiler warnings. Unlike the other types, static analysis warnings are not enabled by default. Before the Roslyn compiler was introduced, they were part of a completely separate tool. So, a significant number of developers have never used them.

Historically, Microsoft has been reluctant to add new compiler warnings. Since they are enabled by default, adding new ones was considered to be a breaking change. Hypothetically, code compiled in C# 7 and not compile in C# 8 if a warning was added and TreatWarningsAsErrors is enabled.

Starting in C# 9, Microsoft added the concept of C# Warning Waves. These are additional compiler warnings, meaning you don’t need to install another tool or package, but they aren’t enabled by default. To use them, you must set the AnalysisLevel in the project file to 5 or higher.

About the Author

Rate this Article