title: Need some clarification about the static constructor VS static field initializer story in C#
body: <p>A couple of days ago I asked myself about the difference, if any, between initializing static fields via 
  the static constructor and doing so by using a static field initializer (inline initialization of a static field at the point of declaration). </p>
  
  <p>After reading plenty of stackoverflow questions on the subject and the famous <a href="https://csharpindepth.com/articles/BeforeFieldInit" rel="nofollow noreferrer">Jon Skeet's article on the beforefieldinit flag</a> I've now a much better understanding of the difference between the two initialization strategies.</p>
  
  <p>There is one point that I'm not sure about, mostly because I wasn't able to find any official documentation about it. </p>
  
  <p>The static construcutor <a href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors" rel="nofollow noreferrer"><strong>is guaranteed to be executed only once</strong></a> and I think this holds true even in multi threading scenarios (when different threads create instances of the class and / or use static members of the class. In any case, the static constructor runs once and only once). </p>
  
  <p>Is this true even for the inline initialization of the static fields ? Is the inline initialization of a static field guaranteed to be executed once even in multi threaded scenarios ? </p>
  
  <p>Another point I'm still missing is what are the practical consequences of this difference in the initialization of the static fields of a class. Put another way, I would like to understand when the correctness of a piece of code can be affected by the choice of initializing a static fied inline at the point of declaration (instead of using the static constructor). </p>
  
  <p>Most of the time (this depends mostly on the type of code that I usually work on, namely web applications) I use static readonly fields in service classes to store things that are used by the service I'm writing to perform computations or taking decisions. I decide to put these things inside static fields because they need to be the same for all the possible instances of the class I'm writing, they are actually <em>invariants</em> that don't belong to a particular instance, but instead they belong to the algorithm itself. </p>
  
  <p>This is an example: </p>
  
  <pre><code>public class SomeInterestingService 
  {
     private static readonly int ConstantNumber = 13;
     private static readonly string[] Names = new[] { "bob", "alice" };
  
     private readonly INumberGenerator numberGenerator;
  
     public SomeInterestingService(INumberGenerator numberGenerator)
     {
        this.numberGenerator = numberGenerator ?? throw new ArgumenNullException(nameof(numberGenerator));
     }
  
     public int ComputeMagicNumber() 
     {
        int answer = this.numberGenerator.GetNumber();
  
         foreach(var name in names)
         {
            answer += name.Length;
         }
  
         answer += ConstantNumber;
         return answer;
     }
  }
  </code></pre>
  
  <p>In code like this, is there any practical difference in chosing static constructor initialization or inline initialization of the static fields <code>ConstantNumber</code> and <code>Names</code>, apart from the difference in performance (inline initialization is more performant due to runtime optimizations that are not possible when using the static constructor) ? </p>
  
  <p>Can the correctness of the code above be affected by the coiche in any strange corner case ? (I think not)</p>