首页 > Windows开发 > 详细

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

时间:2015-01-09 01:23:14      阅读:318      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!