what is Object reference not set to an instance of an object?  

  RSS

TopicCreator
(@topiccreator)
Eminent Member Moderator
Joined: 1 year ago
Posts: 12
12/06/2018 2:57 pm  

i have got this error many times but i can't understand that why it comes.

please help me.

thanks


ReplyQuote
pankaj Gupta
(@pankaj-gupta)
Active Member Moderator
Joined: 1 year ago
Posts: 6
12/06/2018 4:08 pm  

Hi TopicCreator,

They are usually very simple problems caused by not adding additional logic to ensure that objects have valid values before using them.

The following code will throw a NullReferenceException if the variable “text” being passed in is null. You can’t call ToLower() on a null string.

public void Show(string text)
{
     //Throws exception if text == null
     if (text.ToLower() == "Hello World")
     {
          //do something
     }
}

ReplyQuote
Share:
  
Working

Please Login or Register