When you re-specify a parameter with the default value, you can explicitly assign a value to the name of the specified parameter. When it is implicitly specified, it is inferred by the c # compiler based on the sequence of method parameters.
Sample Code:Copy codeCode: void M (int x = 9, string s = "a", DateTime dt = default (DateTime ))
{...}
Main ()
{
M (); // use the default value
M (8, "B"): // specifies the method parameter implicitly. The default value is not specified.
M (6, "v", DateTime. Now); // same as above
M (6, dt: DateTime. Now); // explicitly specify the parameter name and pass the value of the specified parameter
}
Guiding principles for use:
1. You can specify the default value for methods and parameters.
2. Parameters with default values must be defined after parameters without default values
3. The default parameter must be a constant.
4. default values cannot be specified for ref and out parameters.