in C# does Static constructor run for each initialization of object, or only once?

后端 未结 2 727
一整个雨季
一整个雨季 2021-02-04 22:16

in my Class I have a static dictionary of strings object which contains a big number of Items (it reads from a file and initial them) I wrote a static constructor to do so and i

2条回答
  •  青春惊慌失措
    2021-02-04 22:41

    It runs one time only during the lifetime of the application.

    From MSDN - Static Constructors:

    A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or any static members are referenced.

提交回复
热议问题