Object reference not set to an instance of an object

The very first error the developer often face and it irritates so much ,  and we don’t know what the hell is happening.
So know relax and diagnose as following.It occurs when


1. We try to use an ojbect or variable that is not filled in with data or it is totally blank
a

Example : int a;
if I try to write int b = a+ a; 
It might give the above mentioned error
———————————————————————————————————————————–
2. If we try to access the index number of collection that is not populated like list or datatable that is empy and i try to loop through it then it gives the same error
———————————————————————————————————————————-
3. If we try to use an object whose new instance is not created then it gives the same error.

like FileInfo FI ;

string myFileName = FI.Name;
Then the above mentioned line will give the same error.
———————————————————————————————————————————–
Bottom line is whenever our object/variable is empty or null then it gives the error

Object reference not set to an instance of an object

If you still face problem then post here in comments i’ll help you out.

Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *