+ 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
8 ответов
+ 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
+ 3
Iam programming in c# and Iam sorry but I dont understand what you mean, can you give me another example please?
+ 3
Thank you very much and this is an instance or for example Person p = new Person("Alice",8) or?
+ 2
self and cls
+ 1
new Person(name="Alice", age =8)
instead of
new Person("Alice", 8)
The first is with named parameters, the second without.
+ 1
self and cls is the definite answer used in python
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.
0
Yes.