When you reassign a parameter that assigns a default value, you can explicitly assign a value to the specified parameter name, which is inferred by the C # compiler based on the order of the method parameters, as implicitly specified.
code example:
Copy Code code as follows:
void M (int x=9,string s= "A", DateTime dt = Default (DateTime))
{...}
Main ()
{
M ();//Use default value
M (8, "B")://Implicitly Specify method parameters, no default value specified
M (6, "V", DateTime.Now);/ibid.
M (6,dt:datetime.now),//explicitly specifying the parameter name, passing the value for the specified parameter
}
Guiding principles for use:
1. You can specify default values for methods and parameter attributes
2, has the default value parameter, must define after the parameter which does not have the default value
3, the default parameter must be a constant
4, ref, and Out parameters cannot specify default values