whytheq
whytheq

Reputation: 35605

Initializing a class using a static constructor?

In what situations do I initialize a class using a static constructor?

Upvotes: 1

Views: 88

Answers (2)

Renatas M.
Renatas M.

Reputation: 11820

From here:

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

Upvotes: 4

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

When your class uses some static members that need to be initialized or when you want to ensure that some initialization code specific to this class is guaranteed to be executed only once for the entire lifetime of the AppDomain.

Upvotes: 0

Related Questions