Did it with .NET - A Higher Calling (revisited)
… already have equivalents in the .NET Framework 3.5.
1. Filter = Where
2. Map = Select
3. Reduce = Aggregate
Each of these are implemented as extension methods for IEnumerable. So, we can rewrite the code like this:
static void Main()
{
var numbers = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
var sum = numbers.Where(x => (x % 2) == 0).Select(x => x * x).Aggregate(0, (x, y) => x + y);
Console.WriteLine(”Sum: {0}”, sum);}
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « May | Aug » | |||||
| 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 | 31 | |||||
RSS feed for comments on this post · TrackBack URI
Leave a reply