-1

I have the following but some of the fields are null and causes an error:

  Value cannot be null.
 Parameter name: source
 at System.Linq.Enumerable.Where[TSource](IEnumerable`1 source, Func`2 predicate)


foreach (var value in users.entries.Where(x => (x.field1 || x.field2 || x.field3) && 
       !x.field4 && !x.field5))                   
 {
   //code 
 } 

 

How can i do a check for nulls in the following expression , so check for the fields , field1,field2, field3,field4,field5 ?

Abbey
  • 153
  • 2
  • 11

1 Answers1

0

looking from the error its likely your users.entries was null so you could not call Where on it.

Value cannot be null. Parameter name: source

Here source is the first parameter of the Where(...) extension

try this


if (users?.entries is null) {
  // handle null
}
else  {

   foreach ...
}
Madushan
  • 6,977
  • 31
  • 79