A first aspect of local variables is their declaration and the scope in which they are available. Declaring a local variable happens in C style, with the type preceding the name:

int a;long b;string c;

Using a comma separator, you can declare different variables of the same type on the same line:

int x, y, z;

Note: Naming Style

Although nothing in the language cares about or mandates the naming pattern used for local variables, here are some useful recommendations to ensure code readability. The short answer is camel casing, where the first letter of a variable’s name is lowercase and subsequent starting letters of concatenated words are uppercase. For example, firstName and htmlDocument are both valid camel-case identifiers.

Camel ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.