Reputation: 2881
I have a linq statement that looks like this:
if(items.Any(x => x.CustomerID == 4))
{
}
however, I want to find an object in my list of items that not only contains the customerID of 4 but also a designID of 6.
I know I can do this:
if(items.Any(x => x.CustomerID == 4) && items.Any(x => x.DesignID == 6))
{
}
but this may not work since I need to find the same object that has both these values (this would check individually if these exist). Is there a way to combine these?
Upvotes: 2
Views: 7015
Reputation: 223207
You can combine two conditions like x.CustomerID == 4 && x.DesignID == 6
if(items.Any(x => x.CustomerID == 4 && x.DesignID == 6))
Upvotes: 9