码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-01-09 01:23:37      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

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()根本没有被执行,这里还不能很好的理解其原因。

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

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!