listOfJediProducts.Sum(p => p.Cost);
This runs the selector lambda expression over each element in the sequence (returning Cost in this case). The Sum
function is then run on the "implicitly returned" IEnumerable, which obviously calculates the sum and returns it.
It is worth noting that the above is similar to writing:
listOfJediProducts.Select(p => p.Cost).Sum();
Which may be a little more obvious (if not verbose) in understanding what my first example does.
I say "implicitly returned" because Sum only makes sense on an IEnumerable of numbers, the internal workings are probably doing something closer to this:
int total;
foreach (Product p in listOfJediProducts)
total += p.Cost;
return total;