Keywords in C#

A keyword is a sequence of characters, such as identifiers, but it is used as reserved by the C# compiler except that it can be used as the identifier when prefixed with the @ character.
The C# language does support the @ character to prefix a variable name, but it is not common practice to use it. Listing 1-3 shows the usage of the keywords in a method.



Listing 1-3. Example of the Keywords

Code Snippet
  1. static void Main(string[] args)
  2. {
  3.     int a = 100, @int = 100;            /* int is keyword and @int used
  4.                                          * as identifier */
  5.     try {                               /* try is keyword */
  6.   Console.Write(a / @int);
  7.     }
  8.     catch {
  9.    throw;
  10.     }                            /* catch and throw is keyword */
  11. }


List of Keywords in C#

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

Post a Comment