How can I run a static constructor?

前端 未结 10 1335
面向向阳花
面向向阳花 2020-12-08 02:15

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

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 02:50

    Static constructors are NOT always called when accessing a static method!

    I noticed that if you call a static method in a base class, the static constructor of the super class is NOT called. This unexpected behavior has bitten many times.

提交回复
热议问题