Last week I started an ongoing section during the Virtual Brown Bag where I go over a Linq function (or two). The general idea is that although most people ‘use’ Linq, there are lots of functions that are overlooked.
In this blog post I will demonstrate basic usage cases for the Linq Sum function.
Numbers
If you have a collection of numbers and you want the sum of their values, then simply call Sum. It can’t get any easier.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Non-Numbers
If you want to sum a collection that isn’t made up of numbers, then you will be forced to specify which number property you would like to sum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
These tests can be found in my Learning Solution on GitHub and found in the Learning CSharp project : http://github.com/RookieOne/Learning