Improvements to Lambda expressions
A Lambda expression is a way to represent an anonymous method. It allows us to define the method implementation inline.
A delegate type may be created from any Lambda expression. The types of a Lambda expression's parameters and return value determine the delegate type to which it can be transformed. A Lambda expression can be changed to an Action delegate type if it doesn't return a value; otherwise, it can be converted to one of the Func delegate types. In this section, we will learn about the improvements C# 10 brings to Lambda expressions.
Inferring the expression type
C# language compiler will now infer the expression type if the parameter's types are explicit and the return type can be inferred. For example, consider the following code snippet where we defined a Lambda expression to find the square of the given integer:
Var Square = (int x) => x * x;
In the preceding code, the parameter x type is specified...