Identifiers are general terms suitable for variables, classes, methods, and various other user-defined objects.
Following naming rules when writing code can make the program easier to understand and read; it can also provide its functional information, such as whether it is a constant, package name or class, etc., which can help you understand the program.
An identifier is composed of a series of characters, including upper and lower case letters, numbers, underscores (_) and @ characters. Identifiers cannot start with numbers and cannot contain spaces. Examples of legitimate identifiers are Welcome1, _value, m_inputField1 and button7. The name 7button is not a legitimate identifier because it starts with a number. The input field is also an illegal identifier because it contains a space. C# case sensitive - uppercase and lowercase letters are considered different letters, so a1 and A1 are different identifiers.
The @ character can only be used in the first character of the identifier. An identifier with the @ prefix is called a verbatim identifier. This is useful when establishing an interface with other programming languages. The character @ is not an actual component of the identifier, so this identifier may be considered as a normal identifier without a prefix in other languages. Allows the prefix of @ to keywords for identifiers, such as @class, @bool, etc. But it is highly recommended not to do so.
C# identifiers are still a common thing. Here we mainly introduce the usage of C# identifiers, including introducing the static method and bool formal parameters.
Usage in C# identifiers
In the C# specification, @ can be used as the first character of the C# identifier (class name, variable name, method name, etc.), allowing keywords in C# to be retained as C# identifiers defined by itself.
class @class
{
public static void @static(bool @bool)
{
if (@bool)
("true");
else
("false");
}
}
class Class1
{
static void M()
{
@class.@static(true);
}
}
Note that @ although appears in the C# identifier, it is not part of the C# identifier itself. Therefore, the above example defines a class named class and contains a method named static and a formal parameter with the parameter named bool. This brings convenience to cross-language porting. Because a word is used as a reserved keyword in C# , but maybe not in other languages.