title: Static field initialization order (C#) - can someone explain this snippet?
body: <p>I am a C++ programmer learning C#. I am currently reading C#4.0 in a Nutshell.</p>
  
  <p>I have come accross this statement/snipet on page 74:</p>
  
  <blockquote>
    <p>Static field initializers run in the
    order in which the fields are
    declared. The following example
    illustrates this: X is initialized to
    0 and Y is initialized to 3.</p>
  </blockquote>
  
  <pre><code>class Foo
  {
      public static int X = Y; // 0
      public static int Y = 3; // 3
  }
  </code></pre>
  
  <p>I dont understand how X can be assigned the value in Y, without Y being first declared. Am I missing something here?</p>
  
  <p>As an aside, coming from a C++ background, I tend to use the term ctor for constructor - however, I haven't yet come accross the term in C# - is the term ctor also used in the C# world?</p>
  
  <p><strong>[Edit]</strong></p>
  
  <p>A further example on the same page (in the book mentioned earlier) is this:</p>
  
  <pre><code>class Program
  {
      static void Main() { Console.WriteLine (Foo.X); } // 3
  }
  class Foo
  {
      public static Foo Instance = new Foo();
      public static int X = 3;
      Foo() { Console.WriteLine (X); } // 0
  }
  </code></pre>
  
  <p>The book states (for the example above):</p>
  
  <blockquote>
    <p>The example prints 0 followed by 3
    because the field initializer that
    instantiates a Foo executes before X
    is initialized to 3:</p>
  </blockquote>
  
  <p>I have some further questions w.r.t the examples. </p>
  
  <ol>
  <li><p>Both examples appear under the section entitled <strong>Static constructors and field initialization order</strong> however, the code examples dont show a static ctor - atleast, not one that I can easily recognise. I was expecting a static ctor to have the same name as the class, be parameterless and be preceeded by the '<em>static</em>' keyword. So I dont see how the examples relate to the section heading. What am I missing here?</p></li>
  <li><p>In the second example, the (non static) ctor prints out the value of X - which had <strong>explicitly</strong> been assigned the value of 3 in the previous line - and yet, the output printed out is 0. Why?!</p></li>
  </ol>