Closed gaufung closed 1 day ago
在 C#
12 之后, Lambda
表达式的参数可以使用默认参数。举例来说,在 C#
12 之前,我们的 lambda 定义如下
// Before C# 12
var IncrementBy = static (int source, int? increment) =>
{
return source + (increment ?? 1);
};
那么现在可以这样使用
var IncrementBy = static (int source, int increment = 1) =>
{
return source + increment;
};
https://devblogs.microsoft.com/dotnet/refactor-your-code-with-default-lambda-parameters/