Copy the codeThe code is as follows:
static string GetStr(string s = "a", int i = 10, string r = "rrrr")
{
return s + i + r;
}
When calling, you can use the following methods to call
Copy the codeThe code is as follows:
GetStr();
GetStr("abcde");
GetStr("abcde", 100);
GetStr("abcde", 100, "hjklmn");
Moreover, the order of parameters cannot be changed, and one parameter cannot be skipped to use the subsequent parameter type, so there will be a problem. What should I do if I want to call this method and only want to use the first and third parameters?
In fact, in terms of calling optional parameters, Microsoft has introduced named parameters, i.e.
GetStr(s: "abcde", r: "hijklmn");Just mark the parameter name. (The named parameter can only be the parameter name of the original method followed by the colon ":")
In this way, the reloading in the future can save a lot of trouble. Save a lot of code overloading methods