How to avoid conflicts with keywords in C#

As a programmer, we all should be aware that keywords of a programming language cannot be used as identifiers. That is the case for C# as well. We cannot use a keyword as an identifier. As we are aware that .NET framework is multilingual such conflicts can happen when we are referring libraries written in another language. An identifier in the external library can be conflicting with C# language.
The way to avoid this is by using the ‘@’ symbol as a prefix to such identifiers. Ideally we cannot use ‘class’ as an identifier in C#. But this can be made possible by using it as ‘@class’. This is legal and is same as ‘class’.

This is not the case for contextual keywords. They can be used as identifiers without ‘@’ symbol. Ambiguity cannot arise within the context in which they are used.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s