Reputation: 55
I am reading the answer to this question: (Is there a better way of calling LINQ Any + NOT All?). Why does this handle not all conditions? Sorry for creating a new question, but I don't have enough reputation to add a comment on the original question.
var anyButNotAll = mySequence
.Select(item => item.SomeStatus == SomeConst)
.Distinct()
.Take(2)
.Count() == 2;
Upvotes: 3
Views: 77
Reputation: 203828
If the condition is always false (or always true) then when projecting the sequence using the condition and calling Distinct
there will be 1 result, not two, so Count() == 2
will return false, not true.
Upvotes: 2