Declarations

Declarations enable definition and announcement of the existence and nature of program data. There are two forms of declaration in C#: simple declaration and declaration with initialization. A simple declaration takes the following form:

<type> <identifier>;

The type may be any C# or user-defined type. The identifier is any valid identifier as defined in Chapter 2, “Getting Started with C#.”

A declaration with initialization looks like this:

<type> <identifier> = <expression>;

The type and identifier are the same as the previous example. The equal sign takes the evaluated expression on its right and loads it into the variable declared on the left. The expression can be any valid C# statement evaluating to the type of variable ...

Get C# 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.