Assignment

Besides declaration of local variables, there’s also the need to initialize them before they can be used. C# is very strict about not permitting the use of uninitialized variables because that’s a very common source of errors found in other languages. For this very reason, the following fragment won’t compile:

int x;// Error: Use of unassigned local variable 'x'.Console.WriteLine(x);

To ensure variables are properly assigned before they get used, C# has several rules on definite assignment, based on static program flow analysis. I won’t go into detail about those, but I’ll sometimes mention some of the rules in passing.

Assignment is the act of substituting the contents of the storage cell associated with ...

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

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