+ 5

What is a named parameter

Hey guys I read about it in the internet but I dont understand it can anyone please tell me what this is in an easy way? Thank you very much

5th Oct 2017, 6:48 PM
Elsayed Salama
Elsayed Salama - avatar
8 Answers
+ 2
Named parameters are nice. Because it makes you code more readable And you can change the order of the parameters. The parameter are recognized by there name so the order is no longer important. But to be honest I do not use them, it is to much work and not enough benefits. class Program { static void Main() { // Call the Test method several times in different ways. Test(name: "Perl", size: 5);//use named parameters Test(name: "Dot", size: -1); Test(6, "Net"); // use parameters without name, standard Test(7, name: "Google");//mixed } static void Test(int size, string name) { //size and name are the names of the parameters Console.WriteLine("Size = {0}, Name = {1}", size, name); } } https://www.dotnetperls.com/named-parameters
6th Oct 2017, 6:52 PM
sneeze
sneeze - avatar
+ 3
Iam programming in c# and Iam sorry but I dont understand what you mean, can you give me another example please?
5th Oct 2017, 7:09 PM
Elsayed Salama
Elsayed Salama - avatar
+ 3
Thank you very much and this is an instance or for example Person p = new Person("Alice",8) or?
5th Oct 2017, 7:19 PM
Elsayed Salama
Elsayed Salama - avatar
+ 2
self and cls
11th May 2020, 12:32 PM
youssef benslimane
youssef benslimane - avatar
+ 1
new Person(name="Alice", age =8) instead of new Person("Alice", 8) The first is with named parameters, the second without.
5th Oct 2017, 7:17 PM
1of3
1of3 - avatar
+ 1
self and cls is the definite answer used in python
19th May 2020, 2:10 AM
Puxle1Z
0
In some languages you can call a function like that : f(x = 5) instead of f(5) Makes it easier to read, when you have more than one parameter. Not possible in Java.
5th Oct 2017, 7:06 PM
1of3
1of3 - avatar
0
Yes.
6th Oct 2017, 4:51 AM
1of3
1of3 - avatar