Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static field/property initialization

If I have a type like this:

public struct Effect
{
    public int Value { get; set; }

    public static int MinValue = Int32.MinValue;
}

Would MinValue be initialized only ONCE, just like the execution of a static constructor? Or should I initialize MinValue inside a static constructor?

Would this be any different for classes?

like image 526
Joan Venge Avatar asked Nov 27 '25 20:11

Joan Venge


1 Answers

Yes, it would initialize exactly once, before static constructor execution. Same for reference types (classes).

like image 71
Victor Haydin Avatar answered Nov 30 '25 09:11

Victor Haydin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!