0 out of 2 rated this helpful - Rate this topic

10.4.4 Field initialization

Visual Studio .NET 2003

The initial value of a field, whether it be a static field or an instance field, is the default value (Section 5.2) of the field's type. It is not possible to observe the value of a field before this default initialization has occurred, and a field is thus never "uninitialized". The example

using System;
class Test
{
   static bool b;
   int i;
   static void Main() {
      Test t = new Test();
      Console.WriteLine("b = {0}, i = {1}", b, t.i);
   }
}

produces the output

b = False, i = 0

because b and i are both automatically initialized to default values.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.