I have a method returning IEnumerable object, but I found that sometimes (on error) the method returns null value of IEnumerable.
The method looks something like this.
IEnumerable<string> function(String param1, String param2)
{
IEnumerable s = null;
s = (some query over here);
return s;
}
When I call this method with param2, the function internally fails and returns s which is null at this time.
So, to detect this I used,
IEnumerable<string> a = function(1,0);
if (a.count<string> > 0) //not working
if (a == 0) //not working.
What is the correct method to use IEnumerable and check whether it is null before any other operation?
Yours
s = (some query over here);is returning null. That is why you are getting the exception.Later your check should be:
and
You can combine both as: