IAC 2024 - IA Fast Track to Search Focused AI Solutions
Difference between identifier and keyword
1. Difference between Identifier and Keyword in C#
S.No Identifier Keyword
1 Meaning: Meaning:
A C# identifier is a name given Keywords are predefined reserved
to a class, delegate, interface, identifiers that have special
method, namespace or meanings to the compiler.
variable.
2 What it consists of ? What it consists of ?
Must be any combination of Must be only letters.
letters, numbers, and
underscores.
3 Upper case / Lower case / Upper case / Lower case / Both ?
Both ? Most of the keywords are
Allows both Uppercase and Lowercase.But,only Namespaces,
Lowercase. Types and Members have their first
character in uppercase.
4 Whether Unicode characters Whether Unicode characters are
are allowed or not ? allowed or not ?
Identifiers can begin with an Unicode characters are not used in
allowed Unicode character or any C# keywords
an underline. But,we need to
use nonformatting Unicode
characters in any part of an
identifier.
i.e., u0027format // error –
Unicode formatting character
which is not allowed.
5 Whether it can be used to Whether it can be used to name
name classes, methods, or classes, methods, or variables ?
variables ? We cannot use keywords for
The purpose of Identifier is to naming classes, methods, or
provide names to variables.
namespaces, classes,
methods, variables, and
interfaces.
Note: Keywords cannot be used as identifiers in your program unless they include the "at"
sign (@) as a prefix. For example, @new would be a legal identifier; but, new is not,
because it is a keyword.
References:
http://www.dotnetspider.com/forum/161699-Are-C-Keywords-lowercase-or-uppercase.aspx
http://www.dotnetuncle.com/csharp/161-csharp-keywords-case.aspx