30
1
using System;
2
3
public class Program
4
{
5
public static void Main()
6
{
7
int result = 0;
8
9
// positional
10
result = Add(1, 2, 3);
11
Console.WriteLine(result);
12
13
// named
14
result = Add(first: 1, second: 2, third: 3);
15
Console.WriteLine(result);
16
17
// named, out of order
18
result = Add(third: 3, second: 2, first: 1);
19
Console.WriteLine(result);
20
21
// named, out of order, but invalid
22
// ERROR: CS8323 Named argument is used out-of-position but is followed by an unnamed argument
23
// result = Add(third: 3, 2, 1);
24
}
25
26
static int Add(int first, int second, int third)
27
{
28
return first + second + third;
29
}
30
}
Cached Result