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.
Use Func<T> for first class functions - C# Tutorial
From the course: Advanced C#: Functional Programming Patterns
Use Func<T> for first class functions
Since functions are such a key part of functional programming, we should spend a few minutes talking about how to work with them in C#. In functional programming, we use them in variables. We store functions in dictionaries and collections. We work with them as parameters into a function. We can even create higher-order functions that return a function from the method call. In C#, there are three main ways of representing functions: methods, delegates, and lambda expressions. Of these three, the delegate and lambda expression are the most useful in functional programming. Delegates have been around forever in .NET. In recent years, Microsoft has created a number of generalized delegates that are useful, so you typically don't have to create your own custom delegates anymore. And the two that are most used in functional programming is Func<T> and Action<T>. Now Func<T> takes some arguments and returns a value, Action<T> takes some arguments but returns void. And if you think about it…