0

Named arguments

Am I right to assume that when you are declaring a method’s parameters you HAVE to give each parameter a name. Thus, ALL arguments are “named arguments”.

9th Dec 2021, 9:24 AM
Gregory Davies
3 Respostas
- 1
yes and also which type of data.
9th Dec 2021, 9:46 AM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 1
Well, "Named Parameters" are a feature of C# that can match a parameter passed in, with a name. Previously parameters could only be evaluated sequentially as they were declared. Example: public int AddNumbers(int firstNum, int secondNum). To call this method, we would need to send a first number then a second number, AddNumbers(1,2), in the order we declared them. Using the named parameter feature we can pass them in any order but, we have to tell c# which parameter we are passing eg AddNumbers(secondNum:2, firstNum:1).
17th Dec 2021, 7:39 PM
Kail Galestorm
Kail Galestorm - avatar
0
Thanks Kail!
26th Dec 2021, 1:26 AM
Gregory Davies