C#4: Why does this static field always get initialized over-eagerly?
- by TheSilverBullet
I am looking at this excellent article from Jon Skeet at this location:
http://csharpindepth.com/Articles/General/Beforefieldinit.aspx
While executing the demo code, Jon Skeet says that we can expect three different kinds of behaviours. To quote that article:
The runtime could decide to run the type initializer on loading the
assembly to start with... Or perhaps it will run it when the static
method is first run... Or even wait until the field is first
accessed...
When I try this out (on framework 4), I always get the first result. That is, the static method is initialized before the assembly is loaded. I have tried running this multiple times and get the same result. (I tried both the debug and release versions)
Why is this so? Am I missing something?