关于C#静态方法调用问题

C# Code

public class TestClass
{
private static string Str = string.Empty;
public TestClass()
{
if (string.IsNullOrEmpty(Str))
{
Str = "TestStr";
}
}
public static string GetValue()
{
return Str;
}
}

//以上代码中Str是一个需要在程序初始化时根据实际情况赋值并作为静态属性存放于内存中,方便程序运行过程当中取值

当通过TestClass.GetValue()方法取值时,结果却不是"TestStr"而为"";通过调试追踪发现,public TestClass()根本没有被执行,这里还不能很好的理解其原因。

原文地址:https://www.cnblogs.com/liuxinqi/p/Byron_20150108001.html