From the course: Advanced C#: Functional Programming Patterns

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Map with LINQ SELECT

Map with LINQ SELECT

In this video, and in the next video, I'll look at how to work with functional map in .NET and C#. So I'm working with these methods. For this first video, I'll look at the code in these first two methods, SelectWithNoTransform and SelectWithMathTransform. As I mentioned in the slides, functional map, the equivalent of that in .NET is LINQ, the LINQ Select extension method. The idea of this is to apply a function to every item in a list. And in .NET when we're talking about a list, we're talking about arrays, and we're talking about types that implement IEnumerable< T >. The purpose of doing a map is to transform the items in the list. Our first line of code is creating an ImmutableList< int > called numbers. And because it's an immutable list, I use the create methods to generate the immutable list. That's what I'm doing here, CreateRange, and then I'm passing in Enumerable.Range. And that gives me 50 integers. To work with Select, there's two general ways of doing this in C#. I can…

Contents