Collections & LINQ · Lesson 11

Several queries

Two Where calls can disagree. Read each one.

How it works

big keeps prices of at least 20, so only 25. small keeps prices below 10, so only 8. They are separate queries over the same array. Printing both shows 25, then 8. Changing one predicate does not change the other.

A working example

var prices = new[] { 12m, 8m, 25m };
var big = prices.Where(p => p >= 20m);
var small = prices.Where(p => p < 10m);
Console.WriteLine(big.Sum());
Console.WriteLine(small.Sum());

Expected output

25
8
Try this
Try the filter on a smaller list.