Identifiers in C#

Identifiers are names used in the application to identify a namespace, class, method, variable, delegate, interface, and so on.
In every programming language 'Identifiers' is as important as the language itself. Without the identifiers it is difficult to consider a high level language of high level. It take important part in making the language natural and user friendly. 

Figure given below demonstrates the possible forms of the identifiers and also demonstrates the possible combination of the characters and digits used to define an identifier.

  • An identifier is composed of the Unicode characters or it can start with an underscore character or characters (_) along with other characters, such as _ identifier or _iden77tifier, or \u005F \u005FIdentifier (compiled as __Identifier).
  • An identifier can start with the at sign (@) as its prefix, such as @int (as used in Listing 1-2), and it is referred to as the verbatim identifier. To use a keyword as an identifier, the @ needs to be the prefix for the keyword.
  • Unicode escape is used to define an identifier, such as “cl\u0061ss,” when the C# compiler compiles “cl\u0061ss” as a class.

Example of the Identifier

Code Snippet
  1. using System;
  2. /* Ch01 is the identifier to name the namespace*/
  3. namespace Ch01
  4. {
  5.     /* Program is the identifier to name the class */
  6.     class Program
  7.     {
  8.         /* Main is the identifier to name the method */
  9.         static void Main(string[] args)
  10.         {
  11.             /* a and _a is the identifier to name the variable */
  12.             int a = 10, _a = 20;
  13.             /* Verbatim identifier - start with an @ prefix */
  14.             int @int = 10;
  15.             Console.WriteLine("{0}\t{1}\t{2}", a, _a, @int);
  16.         }
  17.     }
  18. }

This program will produce the output:
10      20      10

Post a Comment