[英]C# NullReferenceException with static class
I have a static class: 我有一个静态类:
namespace GVN
{
static class ClData
{
public static string cltNM {get; set;}
}
}
But, when I try to use it, 但是,当我尝试使用它时,
label_nm.Text = ClData.cltNM;
this error appears: ( http://msdn.microsoft.com/library/vstudio/sxw2ez55 ) 出现此错误:( http://msdn.microsoft.com/library/vstudio/sxw2ez55 )
Even if I perform this manually: 即使我手动执行此操作:
ClData.cltNM = "12345";
Before: 之前:
label_nm.Text = ClData.cltNM;
How can I avoid this error? 我怎样才能避免这个错误?
Your problem is that label_nm
is null
, rather than the static
string
variable, or the error is not in fact on the line of code that you've indicated. 您的问题是
label_nm
是null
,而不是static
string
变量,或者错误实际上不在您指定的代码行上。 Even if cltNM
is null
it wouldn't throw a null reference exception on that line. 即使
cltNM
为null
,也不会在该行上抛出空引用异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.