C# supports the use of named arguments, in which you can change the order of arguments passed to a function, by prefixing an argument with the corresponding parameter name.
An argument that is not prefixed with the name of a parameter is considered a positional argument.
Positional arguments must come before named arguments and match the order of the corresponding parameters.
1
2
| // Sample method with 3 parameterspublic void Bark(int numTimes, string sound, double volume) |
Below are some examples of using both named and positional arguments.
1
2
3
4
5
6
7
8
| // Example 1: All arguments are positional<span class="skimlinks-unlinked">myDog.Bark(2</span>, "Woof", 10.0);// Example 2: Only 1st argument is positional<span class="skimlinks-unlinked">myDog.Bark(2</span>, volume: 10.0, sound: "Woof");// Example 3: All arguments are named<span class="skimlinks-unlinked">myDog.Bark(volume</span>: 10.0, sound: "Woof", numTimes: 2); |

