Lambda expressions are not only a powerful way to provide a shorthand notation for anonymous methods, but they are also used in functional programming. In this section, we will go through the advantages of using the lambda expression in the context of functional programming.
In Chapter 1, Tasting Functional Style in C#, we discussed the idea of first-class functions when we were discussing functional programming. If functions are fire class Functions, functions obey value semantics. They can be passed as a parameter, returned from a function, and so on. If we go back to the earlier topic about lambda expressions, we have a project named SimpleLambdaExpression.csproj
, which has the following simple lambda expression:
public partial class Program { static Func<string, string> displayMessageDelegate = str => String.Format(Message: {0}", str); }
Then, we can add...