O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required