简体   繁体   中英

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 )

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. Even if cltNM is null it wouldn't throw a null reference exception on that line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM