-2

When I write something like Console.WriteLine("Insert 2 numbers");

The Quick Actions and Refactorings says "Add argument name 'value'"

Console.WriteLine(value: "Insert 2 numbers");

What difference does this make?

Arynn
  • 1
  • 1

1 Answers1

0

This is a named parameter. It allows you to refer to a parameter by its name instead of its position. It provides two main advantages:

  1. It makes the code easier to read since it clears up what the value is going to be used for in the call (if the parameter has a good name). This can be especially useful for a series if boolean parameters like true, true, false which can become very confusing.

  2. You are free to reorder the parameters. Since you pass the arguments by name, the order may be changed. If you have more than one optional parameter, you would have to add all parameters before the one you drop. With named parameters you don‘t need to do that.

Sefe
  • 13,731
  • 5
  • 42
  • 55