bugfixer
bugfixer

Reputation: 55

Why does this handle not all conditions?

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

Answers (1)

Servy
Servy

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

Related Questions