Oct 19, 2009

Object reference not set to an instance of an object

This post is intended for beginners in .NET Programming

I'm damn sure you will encounter this error a number of times in your early years as a programmer (and even afterwards !)




As shown in the screenshot above, you see a 'object reference not set...' error occured at the place where I am trying to do .ToString() operation on the variable. Now due to some unknown reason, assume that as on line 18, you some how set Result to 'null'. So performing any operation on variables with null value, will result in the above said error.
It is generally good practice that you check for null first before operating on the object/variable.
Happy Coding!

No comments:

Post a Comment