Static constructor can run after the non-static constructor. Is this a compiler bug?

后端 未结 4 472
轮回少年
轮回少年 2020-12-01 21:53

The output from the following program is:

Non-Static
Static
Non-Static

Is this a compiler bug? I

4条回答
  •  时光取名叫无心
    2020-12-01 22:10

    From MSDN Link:

    A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.

    My Guess this is because of the static instantiation of the instance on the last line, but according to MSDN the static constructor should happen before the first instance is called.

提交回复
热议问题