1

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?

3
  • @DJKRAZE create an instance of a static class .. ? Commented Dec 28, 2012 at 20:41
  • 1
    Please try to use better variable names. Highly abbreviated names make reading code much harder than it needs to be, and code completion tools mean you don't actually need to type out long names. Commented Dec 28, 2012 at 20:43
  • A class can be declared static, indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. The main features of a static class are: They only contain static members. They cannot be instantiated. They are sealed. They cannot contain Instance Constructors must Be static Commented Dec 28, 2012 at 20:51

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I did not notice that. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.