developer747
developer747

Reputation: 15958

Linq and anonymous type

select new
{
 Selected = (cvf != null && cvf.Deleted==false)
}

The above statement proceeds to check cvf.Deleted even if cvf is null. Then it throws an invalid object reference error.

How do I fix this?

Upvotes: 0

Views: 85

Answers (1)

Yuck
Yuck

Reputation: 50855

Probably something else going on since && will short-circuit evaluate. That said, try this instead:

select new
{
    Selected = cvf != null
        ? !cvf.Deleted
        : false
};

Upvotes: 1

Related Questions