I want to be able to know which methods return null from .NET Framework.
For example; when I call a search method from IQueryable
, if the search did not find any results will it return null or an empty collection.
We learn some of the methods but when new methods are concerned, I always write additional line of codes which makes harder to read the code.
Is there an easy way to work off this?
EDIT:
How I always encounter this problem is like this:
List<int> ints = new List<int>(); // Suppose this is a list full of data
// I wanna make sure that FindAll does not return null
// So getting .Count does not throw null reference exception
int numOfPositiveInts = ints.FindAll(i => i > 0).Count;
// This is not practical, but ensures against null reference return
int numOfPositiveInts = ints.FindAll(i => i > 0) != null ? ints.FindAll(i => i > 0).Count : 0;
First option is practical but not safe, while second option prevents any null reference exceptions but decreases readability.
Thanks.