Static Constructors in C#

Random tidbit I learned at work yesterday:

Static constructors are called when one of the following two things happen:

  1. The first instance of the class with the static constructor is instantiated
  2. Any static member of that class is used

However, when a struct declares a static constructor, #1 does not apply. That is to say, instantiating an instance of that struct does not actually force the static constructor to be called. #2 is still true for structs, however.

That concludes my geek moment for the day.

Notes

  1. minos reblogged this from caseyliss
  2. caseyliss posted this