是否应该在调用构造函数之前完成静态字段初始化?
下面的程序提供的输出在我看来是不正确的。
new A()
_A == null
static A()
new A()
_A == A代码:
public class A
{
public static string _A = (new A()).I();
public A()
{
Console.WriteLine("new A()");
if (_A == null)
Console.WriteLine("_A == null");
else
Console.WriteLine("_A == " + _A);
}
static A()
{
Console.WriteLine("static A()");
}
public string I()
{
return "A";
}
}
class Program
{
static void Main(string[] args)
{
var a = new A();
}
}https://stackoverflow.com/questions/710793
复制相似问题