Let's suppose I have a very simple IEnumerable
that looks like this:
IEnumerable<string> foo = new[] { "Apple", null, "Orange" };
I would like to check if it contains a null
item. Based on what I found with Google, I can do this as follows:
bool containsNull = foo.Any(item => item == null);
What about the Enumerable.Contains
method? The following seems pretty obvious to me, but I've never seen it this way:
bool containsNull = foo.Contains(null);
Is there any problem with the previous expression that results in the Enumerable.Any
method used instead?