Seleccionar página

Rules for setting identifiers in C#:There are some valid rules for defining a valid C# identifier. These rules must be followed, otherwise we will get a compilation error. In programming languages, identifiers are used for identification purposes. In other words, identifiers are the user-defined names of program components. In C#, an identifier can be a class name, method name, variable name, or label. Example: To clarify the concept, let`s look for the list of keywords and identifiers in the program we wrote in C# Hello World. Here, value is the name of the variable. It is therefore an identifier. Reserved keywords cannot be used as identifiers unless @ is added as a prefix. For example, here are some of the valid and invalid identifiers: Identifiers are the name of entities such as variables, methods, classes, etc. is given. These are tokens in a program that uniquely identify an item.

For example, the following table shows the identifiers and keywords that exist in the example above: Here, the total number of identifiers present in the above example is 3 and the names of these identifiers are: Also, keywords such as long, int, char, etc. cannot be used as identifiers. So we can`t have something like: In addition to rules, there are many identifier naming conventions that are used in the file. NET API. By convention, C# programs use PascalCase for type names, namespaces, and all public members. Additionally, the following conventions are common: Although keywords are reserved words, they can be used as identifiers when @ is added as a prefix. For example, C# has 25 contextual keywords in addition to regular keywords. Contextual keywords have a specific meaning in a limited program context and can be used as identifiers outside that context.

These are not reserved words in C#. Keywords are predefined sets of reserved words that have a special meaning in a program. The meaning of keywords cannot be changed or used directly as identifiers in a program. Here long is a keyword and mobileNum is a variable (identifier). long has special meaning in C#, which means that it is used to declare variables of type long and this function cannot be changed. C# has a total of 79 keywords. All these keywords are written in lower case. Here is a complete list of all C# keywords. The «Hello World!» in the WriteLine method is a string literal. It cannot contain spaces or embedded symbols, such as ? – + ! @ # % ^ & * ( ) [ ] { }. ; : » ` / and . However, an underscore ( _ ) can be used.

An identifier is the name you assign to a type (class, interface, structure, record, delegate, or enumeration), member, variable, or namespace. If you want to know the function of each keyword, I recommend you visit the C# keywords (C# official documents). This statement generates an error at compile time. A name must begin with a letter, which can be followed by a sequence of letters, numbers (0 to 9), or underscores. The first character of an identifier cannot be a number. An identifier is a name used to identify a class, variable, function, or other user-defined element. The basic rules for naming classes in C# are as follows.