📜 ⬆️ ⬇️

C #: Etudes, part 7

Today, a simple sketch, almost no code.

Suppose there is a certain class and its static constructor:
static C()
{ Console.WriteLine("from static ctor"); }

As you know, static constructors are called before the first use of a type. There are no other restrictions, so you cannot control the time of its call (it can be called both at the very beginning of the program and at the first call). In particular, if two classes use each other in static constructors, the order in which these constructors are invoked is not defined.

In general, everything is very difficult. However, write code that is guaranteed to call the above static constructor just in the right place.
')
Console.WriteLine("before static ctor");
//
Console.WriteLine("after static ctor");

Source: https://habr.com/ru/post/113543/


All Articles