FAQ
What is the difference between a parameter and argument?
- A parameter is part of the signature
- An argument is part of the method call
- A named argument uses the parameter name when calling the method.
- Used to clarify the purpose of an argument and define arguments without concern for their position in the parameter list.
- In the method signature, we define a parameter as optional by specifying a default value.
- When passed by value, which is the default, the value of the argument is passed to the method.
- When passed by reference using ref or out, the variable is effectively passed to the method.
- Because of this, passing by reference enable the method to change the value of the parameter and have that change reflected in the calling code.
- A ref parameter requires that the argument is initialized before it is passed.
- The method can modify the value for the ref parameter.
- An out parameter must be declared but does not need to be initialized before it is passed.
- The method must provide a value for the out parameter.
Comments
Post a Comment