, () constuctor. , . , , , .
,
public class Foo
{
public static int Bar = 1;
}
# beforefieldinit. JIT , - , , , .. , , , .
,
public class Foo
{
public static int Bar;
static Foo()
{
Bar = 1;
}
}
IL beforefieldinit. JIT , .
The previous JIT behavior is known as before-field-init semantics, and the second is known as exact semantics. It is important to know the difference between the two, since in some scenarios they can have significant performance.
source
share