LANGUAGE

Local variable declaration

Introduces a local variable, optionally with an initializer. The variable must be definitely assigned before use and assignments must be compatible with its type. Syntax shown is the initialized ordinary local form.

Formal Syntax & Structure

csharp syntaxcsharp
<type> <identifier> = <expression>;

Working Example

Example Snippetcsharp
int books = 4;books = books + 2;System.Console.WriteLine(books);
C# & .NET Reference