title: Is it safe for a class to create instances of itself inside the static constructor?
body: <p>I stumbled upon a problem where i need an instance of the class inside its static constructor. I believed it was not possible to do it so i tried the following:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Console.WriteLine(Foo.someString);
          Console.ReadLine();
      }
  }
  
  class Foo
  {
      public static readonly string someString;
  
      static Foo()
      {
          someString = new Foo().CreateString();
      }
  
      private string CreateString()
      {
          return "some text";
      }
  }
  </code></pre>
  
  <p>To my surprise, it works - the output is "some text". I believed the static constructor must run and complete before instances of the class can be created. <a href="https://stackoverflow.com/questions/2925611/static-constructor-can-run-after-the-non-static-constructor-is-this-a-compiler">This answer</a> shows that this is not necessarily the case. Does this mean that static and instance constructors are independent of each other? And finally, <strong>is it safe to do this (create instances in static constructor)?</strong></p>
  
  <p>p.s. Let's ignore the fact that this can be avoided by using a different approach.</p>