-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaParametersSample.cs
More file actions
23 lines (20 loc) · 1.08 KB
/
LambdaParametersSample.cs
File metadata and controls
23 lines (20 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// ReSharper disable ConvertToLocalFunction
namespace CSharp.Version12;
public static class LambdaParametersSample
{
public static void Run()
{
var addWithDefault = (int addTo = 2) => addTo + 1;
Console.WriteLine($"Lambda with default value: {addWithDefault()}");
Console.WriteLine($"Lambda with provided parameter value: {addWithDefault(5)}");
Console.WriteLine($"Parameter group with default value: {AddWithDefaultMethod()}");
Console.WriteLine($"Parameter group with provided parameter value: {AddWithDefaultMethod(8)}");
var counter = (params int[] xs) => xs.Length;
Console.WriteLine($"Lambda with no params: {counter()}");
Console.WriteLine($"Lambda with provided params array: {counter(1, 2, 3)}");
Console.WriteLine($"Parameter group with no params: {CountMethod()}");
Console.WriteLine($"Parameter group with provided params array: {CountMethod(1, 2, 3, 6)}");
}
private static int AddWithDefaultMethod(int addTo = 2) => addTo + 1;
private static int CountMethod(params int[] xs) => xs.Length;
}