When does below message occur?

Object reference not set to an instance of an object

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

When we create any Class object but do not initialize with New keyword and we are dealing with that object or we are using that object anywhere in our code,then above error occurs.

For Example:-
DataTable dt_project = null;

dt_project.Columns.Add("project_id");
dt_project.Columns.Add("project_name");


In above code,we have not initialized datatable object and still adding columns to it.When we run,it will throw above error.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response