CSharp - Introduction Keywords


Keywords are reserved names.

you can't use them as identifiers.

Here is the full list of C# reserved keywords:

abstract    do          in           protected     true
as          double      int          public        try
base        else        interface    readonly      typeof
bool        enum        internal     ref           uint
break       event       is           return        ulong
byte        explicit    lock         sbyte         unchecked
case        extern      long         sealed        unsafe
catch       false       namespace    short         ushort
char        finally     new          sizeof        using
checked     fixed       null         stackalloc    virtual
class       float       object       static        void
const       for         operator     string        volatile
continue    foreach     out          struct        while
decimal     goto        override     switch
default     if          params       this
delegate    implicit    private      throw

Avoiding conflicts

To use a reserved keyword as identifier, qualify it with the @ prefix.

For instance:

class class  {...}      // Illegal
class @class {...}      // Legal

@ symbol is not part of the identifier itself. @myVariable is the same as myVariable.

@ prefix is useful when using libraries written in other .NET languages with different keywords.

Contextual keywords

Contextual keywords can be used as identifiers-without an @ symbol. These are:

add           dynamic    in        orderby   var
ascending     equals     into      partial   when
async         from       join      remove    where
await         get        let       select    yield
by            global     nameof    set
descending    group      on        value