Mike-Ward.Net

Using Keywords as Identifiers in C#

There are times when keywords and identifiers collide when coding. This is particularly true in code generators but sometimes the keyword really describes the purpose of the identifier (like default or ref for instance). You can come up with clever naming schemes but there is a simpler way. In C#, you can just prefix the identifier with an @ symbol.

Keywords are predefined reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a legal identifier but if is not because it is a keyword. The C# Language

← newer older →
.Net, Technology, Life, Whatever

Recent Posts

Quick Tip - Clear ReSharper's Cache to Fix False Errors
Quick Tip - Refined GitHub
Vertical Layout for HTML Tables
Visual Studio 2017 Installer Quick Tip
VSColorOutput for VS 2017 Released
Quick ReSharper tip for inline templates
NoSQL vs. NewSQL: What's the Difference?
More... (1077)

Donate with PayPal