Linq ambiguity on where and select?

Select is a projection, so what you get is the expression p. Qty > 0 evaluated for each element in somelist i.e. Lots of true/false values (the same number as your original list).

So when you do Count on it, you get the same number. If you look the select will return IEnumerable 0 is a bool) Where filters the results so count runs on the filtered list, and give you the expected results. The type of this is an IEnumerable p.

Qty > 0) because Count has an overload that accepts a predicate to filter by.

Select is a projection, so what you get is the expression p. Qty > 0 evaluated for each element in somelist. I.e.

Lots of true/false values (the same number as your original list). So when you do Count on it, you get the same number. If you look the select will return IEnumerable (because the type of p.

Qty > 0 is a bool). Where filters the results so count runs on the filtered list, and give you the expected results. The type of this is an IEnumerable.

Note you can also do: somelist. Count(p => p. Qty > 0) because Count has an overload that accepts a predicate to filter by.

The first query gives the same as somelist.Count(). It's just the number of elements in the sequence. The call to Select projects each object, but the number of objects remains the same.

The second query gives the number of elements that fulfil the predicate, which is a potentially lower number. The call to Where filters objects from the sequence.

The first query returns an IEnumerable of booleans. The second query only returns elements in the original that match the boolean expression.

The first statement creates an IEnumerable of bools: is the qty field > 0. Since there are 10 records, you get 10 bools. The second return an IEnumerable filtered over the condition.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions