How do I use a C# keyword as a property name?

You can use keywords in C# as identifiers by prepending @ infront of them.

var @class = new object();

To quote from the MSDN Documentation on C# Keywords:

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 valid
identifier but if is not because if is a keyword.

Leave a Comment