C# Language Named and Optional Arguments

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

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.
  • No needs for remembering the parameters position that we are not aware of always.
  • No need to look the order of the parameters in the parameters list of called function.
  • We can specify parameter for each arguments by its 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, a Optional Argument,

  • We can omit the argument in the call if that argument is an Optional Argument
  • Every Optional Argument has its own default value
  • It will take default value if we do not supply the value
  • A default value of a Optional Argument must be a
    • Constant expression.
    • Must be a value type such as enum or struct.
    • Must be an expression of the form default(valueType)
  • It must be set at the end of parameter list


Got any C# Language Question?