title: How can I run a static initializer method in C# before the Main() method?
body: <p>Given a static class with an initializer method:</p>
  
  <pre><code>public static class Foo
  {
      // Class members...
  
      internal static init()
      {
          // Do some initialization...
      }
  }
  </code></pre>
  
  <p>How can I ensure the initializer is run before <code>Main()</code>?</p>
  
  <p>The best I can think of is to add this to <code>Foo</code>:</p>
  
  <pre><code>private class Initializer
  {
      private static bool isDone = false;
      public Initializer()
      {
          if (!isDone)
          {
              init();
              isDone = true;
          }
      }
  }
  
  private static readonly Initializer initializer = new Initializer();
  </code></pre>
  
  <p>Will this work or are there some unforeseen caveats? And is there any better way of doing this?</p>