C# The variable naming rules are: start with a letter or underscore, and may subsequently contain letters, underscores or numbers. case sensitive. Maximum 64 characters. C# keywords cannot be used. The @ symbol cannot be used. Variable names should clearly describe their purpose. Avoid using abbreviations. Be consistent.
C# Variable naming rules
In C#, variable naming follows the following rules:
1. Naming convention
- Start with a letter or underscore.
- Following characters can be letters, underscores or numbers.
- Case-sensitive, for example, "name" and "Name" are different variables.
- CamelCase: For multi-word variables, use uppercase letters to separate words, such as "firstName".
- Pascal nomenclature: For class and method names, capitalize the first letter of all words, such as "FirstName".
2. Length limit
- The variable name can be up to 64 characters.
3. Reserved keywords
- You cannot use C# keywords as variable names, such as "var", "for", "while" .
4. Special characters
- @ symbols cannot be used in variable names.
5. Clear meaning
- Variable names should clearly describe their purpose. For example, for a variable that stores a username, it would be more appropriate to name it "username" rather than "name".
6. Avoid using abbreviations
- Avoid using abbreviations in variable names unless the abbreviation is well known.
7. Consistency
- Keep your variable naming style consistent throughout your code base.
Example:
- Valid variable names: firstName, productCount
- Invalid variable names: 1name,@username, #number
The above is the detailed content of What are the naming rules for c# variables?. For more information, please follow other related articles on the PHP Chinese website!