I use:
if (!ObjectCollection.Any(o => o.Property == SomeValue))
// ...
or:
if (!IntCollection.Contains(42))
// ...
to determine if a collection does not have a particular element, but some people miss the ! negation and misinterpret.
Is there another way to determine that a collection does not contain a particular element that doesn’t use the negation operator? I prefer to stick to dot notation instead of query expression, but maybe a query expression is more readable to someone who misses the bang.
There’s nothing in standard LINQ, but if you really don’t like using
!(which is the approach I’d recommend) you could always write your own extension methods:(You can use these for things like LINQ to SQL as well if you’re just using them as the final call – you wouldn’t be able to use them in nested queries though, as the query translator wouldn’t understand them.)