Variable Naming in C#
As mentioned in the previous section, you can ’ t just choose any sequence of characters as a variable name. This isn ’ t as worrying as it might sound at first, however, because you ’ re still left with a very flexible naming system.
The basic variable naming rules are as follows:
1) The first character of a variable name must be either a letter, an underscore character ( ), or the at symbol ( @ ).
2) Subsequent characters may be letters, underscore characters, or numbers.
There are also certain keywords that have a specialized meaning to the C# compiler, such as the using and namespace keywords shown earlier. If you use one of these by mistake, the compiler complains, however, so don ’ t worry about this.
For example, the following variable names are fine:
myBigVar VAR1 _test
These are not, however:
99BottlesOfBeer namespace It’s-All-Over
Remember that C# is case sensitive, so be careful not to forget the exact case used when you declare your variables. References to them made later in the program with even so much as a single letter in the wrong case prevents compilation. A further consequence of this is that you can have multiple variables whose names differ only in case. For example, the following are all separate names:
myVariable MyVariable MYVARIABLE