What Does Identifier Mean?
An identifier, in C#, is the user-defined name of a program element. It can be a namespace, class, method, variable or interface.
Identifiers are symbols used to uniquely identify a program element in the code. They are also used to refer to types, constants, macros and parameters. An identifier name should indicate the meaning and usage of the element being referred.
C# is a programming language that is compiled and has its implementation such that the identifiers are only compile-time entities. During run time, each identifier will be referred by its reference to the memory address and offset the compiler assigned to its textual identifier token.
Techopedia Explains Identifier
Like in C/C++, identifiers in C# are case-sensitive.
Microsoft recommends the use of Camel or Pascal notations, along with semantics, for naming identifiers instead of the Hungarian notation that was used prior to .NET programming. For example, "employeeSalary" might represent Camel notation wherein the first letter of all the words is capitalized except the first word. Camel notation is used to name private members, fields and parameters. "EmployeeSalary" is an identifier in Pascal notation, as all the words in the identifier begin with an upper-case letter. It is usually used for type names and nonprivate members of a type.
The rules to be followed while using an identifier include:
- It can start only with a letter of the alphabet or underscore(_), but not a number
- It can be a combination of numbers, letters, connectors, Unicode escape sequence, etc.
- It cannot be a C# keyword
- It should not contain white space
- It cannot have more than 511 characters
- It has to be declared before it is referred
- It cannot have two consecutive underscores in its name because such identifiers are used for the implementation
- More than one identifier with the same name cannot be declared within a single scope
An identifier prefixed with "@" is called a verbatim identifier. Although prefixing "@" allows for the use of keywords, which helps in interfacing with other programming languages, it is not a recommended practice.