I am trying to check a type of IEnuemrable<SystemUser>
for null.
I am using this piece of code
var systemUsers = newActActivityPersons.SelectMany(x => x.Person.SystemUsers);
if (systemUsers == null || !systemUsers.Any()) return ;
That isn't working. When I try to do something like systemUsers.ToArray()
or systemUsers.ToList()
I get a null exception. How can I check this for errors?
One of the subsequent x.Person.SystemUsers
could be null. .Any()
returns true if there is one. If you then try to ToList()
afterwards, you might find an x
who's Person
is null.
Check to make sure that x.Person
isn't null before accessing a property on the object.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments