title: Initialization precedence - const vs readonly vs static readonly
body: <h2>Example 1</h2>
  
  <pre><code>private const string _DefaultIconPath = _IconsPath + "default.ico";
  private const string _IconsPath = "Icons/";
  </code></pre>
  
  <p>Value of these strings at runtime:</p>
  
  <ul>
  <li>_DefaultIconPath: "Icons/default.ico"</li>
  <li>_IconsPath: "Icons/"</li>
  </ul>
  
  <hr>
  
  <h2>Example 2</h2>
  
  <pre><code>private readonly string _DefaultIconPath = _IconsPath + "default.ico";
  private readonly string _IconsPath = "Icons/";
  </code></pre>
  
  <p>Compile time error:</p>
  
  <pre><code>A field initializer cannot reference the non-static field, method, or property '_IconsPath'
  </code></pre>
  
  <hr>
  
  <h2>Example 3</h2>
  
  <pre><code>private static readonly string _DefaultIconPath = _IconsPath + "default.ico";
  private static readonly string _IconsPath = "Icons/";
  </code></pre>
  
  <p>Value of these strings at runtime:</p>
  
  <ul>
  <li>_DefaultIconPath: "default.ico" (_IconsPath evaluated to <code>null</code>)</li>
  <li>_IconsPath: "Icons/"</li>
  </ul>
  
  <hr>
  
  <h2>Question</h2>
  
  <p>Why doesn't the compiler throw a compilation error in example 3 similar to example 2?</p>
  
  <p>The order of the declaration matters in the case of <code>static readonly</code> field definitions, but not in the case of <code>const</code> field definitions.</p>
  
  <p>Edit:</p>
  
  <p>I understand why the strings are initialized to those specific values. What I don't understand is why Example 2 throws a compilation error, forcing initialization to occur in a constructor rather than in the declaration of the variables (which makes perfect sense), but Example 3 doesn't behave in the same manner. Wouldn't it make sense to throw the same compilation error forcing the initialization to occur in a static constructor?</p>
  
  <hr>
  
  <h2>Another Example</h2>
  
  <pre><code>private static string test = test2;
  private static string test2 = test;
  </code></pre>
  
  <p>This example demonstrates what I'm trying to explain. The compiler could force initialization of static state in a static constructor (as is does for instance variables). Why does the compiler allow it (or why does the compiler disallow this for instance variables)? </p>