Functional Collection Parameters in C#

While talking through my understanding of the Select method which can be applied to collections in C# with a colleague, it became clear that C# doesn’t seem to use the same names for these type of operations as are used in the world of functional programming.

The responsibility for iterating the collection has been taken away from me and I can just focus on what I want to do with the collection rather than worrying too much about the details. A more declarative approach.

If I want to see the results of that operation I just do the following:

upperCaseValues.ForEach(Console.WriteLine);

MARK
SYDNEY
SUNNY

Filter

Filter applies a predicate against all of the elements in a collection and then returns a collection of elements which matched the predicate.

Conveniently there is actually a built in delegate called ‘Predicate’ which when combined with the ‘FindAll’ method can be used to solve this problem.

Overall

I really like having this high order functions available to us - it has taken away the need to write some of the most boring code that we used to have to write and makes our code more concise and easier to read.