Tag Archives: Optional Parameters

Optional Arguments

The definition of a method, constructor, indexer or delegate can specify that a parameter is optional. Any caller must provide all required arguments but does not have to specify optional ones.

Each optional parameter has a default value as part of its definition that is used if an argument for it is not specified.

public void MyFunction(int parameterOne, string optionalPerameter = "Hello World")
{
}

In the example above the string Hello World will be passed into the function if the caller decides not to pass in an argument for that parameter.

Optional parameters are defined at the end of the argument list, after any required arguments. If the caller provides an argument for any optional parameter it must provide arguments for all previous optional parameters.