Introduction

This chapter talks about the functional programming capabilities of C# and how to use them for a .NET Standard 2.0 library. Let's look at a definition of functional programming: "Functional programming is a style that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data."

Simply put, it means you will be able to use functions as inputs and outputs for other functions. You can also assign them to variables and store them in collections. Have a look at the following code, which explains what we just talked about:

Func<int, int> addNumbers = n => n + 1;var answer = addNumbers(1);answer // 2var range = Enumerable.Range(1, 5);var answers = range.Select(addNumbers);answers // 2, ...

Get .NET Standard 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.