Naming Variables – Rules
When we want the compiler to allocate a memory area for some information which is used in our program we must provide a name for it.It works like an identifier and allows referring to the relevant memory area.
The name of the variable can be any of our choice but must follow certain rules defined in the C# language specification:
- Variable names can contain the letters a-z, A-Z, the digits 0-9 as well as the character '_'.
- Variable names cannot start with a digit.
- Variable names cannot coincide with a keyword of the C# language. For example, base, char, default, int, object, this, null and many others cannot be used as variable names.
A list of the C# keywords can be found in the section "Keywords" in chapter "Introduction to Programming". If we want to name a variable like a keyword, we can add a prefix to the name – "@". For example, @char and @null are valid variable names while char and null are invalid.
0 Comments