If objects contains null or empty then how to validate or check the condition for the same?
How to bool check whether object obj is null or
You shouldn't be a bit surprised that you get a NullReferenceException with this code. The offending part is
obj.ToString()
If you wrote
object obj = null;
string s = obj.ToString();
you would expect a NullReferenceException. Since the call to ToString occurs before the call to string.IsNullOrEmpty, the exception is thrown before there is a check for a null or empty string.