Declaration

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, different variables of the same type can be declared on the same line:

int x, y, z;

Naming Style

Although nothing in the language cares about or mandates the naming pattern used for local variables, there 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 casing ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.