I'm passing a list to a method that operates on the list. However first I want to iterate over the list and check whether or not there are any null values within the list before any further processing takes place.
Initally I thought using the IEnumerable.All() method would help with this, however this method actually checks that all elements of the list satisfy a condition, I'd like to check each element in turn and if any are null then handle this.
This is the (non-working) code that I have already. I'm not sure how I would adapt this for use within an if statement condition.
if (questions == null || questions.Any() == false || questions.All(q => q == null))
{
throw new ArgumentException("Exception raised.");
}
Essentially I want to check:
- Questions isn't null.
- Questions isn't empty.
- Any elements held within questions aren't null values.
The first two have been done, it's just the third.