Declaration Versus (Simple) Assignment

It’s important to realize the fundamental difference between declaring variables and assigning to them. Declaring a variable simply introduces a symbolic name (specified using an identifier) in the containing scope, also specifying its type. Assignment is the act of setting a value for the variable, which can be done multiple times as long as the variable is in scope (unless the variable is declared as constant, that is). The following piece of code

int x = 42;

can be decomposed into two separate discrete steps:

int x;x = 42;

The latter one is what we’re talking about here. It’s called a simple assignment that has the form lhs = rhs. After evaluating the right side (rhs), it gets assigned to the left side ...

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

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