Optional parameters are supported in C #4.0. Assign a constant to a parameter when declaring a method. You do not need to specify each parameter when calling this method.
Public Class A
{
Public Static VoidMain ()
{
//Call the functiona Method
Functiona (StringStr );
}
Public VoidFunctiona (StringA,IntI=1)
{
Do.......
}
}
Note:
1. Optional parameters must be placed behind all required parameters (that is, parameters without default values.
2. The default value is a constant.
Name parameters when calling another method in C #4.0.
You can assign values to the specified parameter names.
Code
Public Class A
{
Public Static VoidMain ()
{
//Call the functiona Method
Functiona (:"Stringa", C: intc );
}
Public VoidFunctiona (StringA,StringB=Default(String),IntC= Default(Int))
{
Do.......
}
}
When you see the optional parameters, naming parameters, and method overloading in the application system, it is difficult to distinguish which method to call.