Named and Optional Arguments
suggest changeRemarks
Named Arguments
Ref: MSDN Named arguments enable you to specify an argument for a particular parameter by associating the argument with the parameter’s name rather than with the parameter’s position in the parameter list.
As said by MSDN, a named argument:
- Enables you to pass the argument to the function by associating the parameter’s name.
- Removes the need to remember the position of a parameter you are skipping.
- Removes the need to look at the order of every parameter in the called function.
- Lets us specify each argument by its parameter name.
Optional Arguments
Ref: MSDN The definition of a method, constructor, indexer, or delegate can specify that its parameters are required or that they are optional. Any call must provide arguments for all required parameters, but can omit arguments for optional parameters.
As said by MSDN, an optional argument:
- We can omit the argument in the call if that argument is optional.
- Every optional argument has its own default value.
- It takes that default value if we do not supply one.
- The default must be a constant expression,
new ValType()for a value type, ordefault(ValType)for a value type. A reference type can use a constant such asnullor a string literal. - Optional parameters must come after all required parameters.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents