Alex Rivera | Logout

How can I run a static constructor?

Asked 2010-04-16T15:09:45.587
58

I'd like to execute the static constructor of a class (i.e. I want to "load" the class) without creating an instance. How do I do that?

Bonus question: Are there any differences between .NET 4 and older versions?

Edit:

  • The class is not static.
  • I want to run it before creating instances because it takes a while to run, and I'd like to avoid this delay at first access.
  • The static ctor initializes private static readonly fields thus cannot be run in a method instead.
Edit
Report

1 Answer

-4

The static constructor runs automatically the first time you access the class. There is no need (or capability) to 'run' it yourself.

answered 2010-04-16T15:12:03.873

Your Answer