O'Reilly logo

Refactoring with Microsoft Visual Studio 2010 by Peter Ritchie

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

Move initialization to declaration

In C# there are various options to initialize variables. Variables include member and local variables. These variables can be simple types (one value) or they can be aggregate types (a composition of multiple values).

The first time a variable that is a simple type is assigned, it is considered initialized. Initialization of aggregate types is more complex. Aggregate types can be designed to be completely initialized via a particular constructor, or the aggregate type may only have a default constructor and initialization must occur through multiple property/field assignments. There's also a hybrid of the two where initialization occurs with both a constructor and field/property assignment.

I emphasize initialized ...

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