Part 4 in a series on new language features in C# 12.

C# logo

Default lambda parameters

A pretty simple addition to the language - you can now provide default values for lambda expression parameters.

var IncrementBy = (int source, int increment = 1) => source + increment;

In the lambda defined above, if you don't supply the increment parameter, it defaults to 1.

Again, interesting, but I've not come across a need to use this yet.

Further reading

https://learn.microsoft.com/dotnet/csharp/language-reference/operators/lambda-expressions?WT.mc_id=DOP-MVP-5001655#input-parameters-of-a-lambda-expression

Example source

https://github.com/flcdrg/csharp-12/blob/main/04-optional-params-lambda/LambdaParameters.cs