What will happen when we run below code?
string str = null;

 Posted by Rajesh_Kumar on 1/21/2014 | Category: C# Interview questions | Views: 2100 | Points: 40

It will throw an error which says that 'Object reference not set to an instance of an object'
Because if the object is null or not assigned any value to it and we are trying to convert it with .ToString then it will throw an error.Because .ToString does not handle Null value.Thats why it will throw an error.
So to avoid such exception,we have to use Convert.ToString() method as it handles Null value.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response