Body
Variable parameter, the last parameter of the parameter must be the most, the variable parameter can only have one;
Examples of C # mutable parameters:
Class Program
{
static void Main (string[] args)
{
Test T = new Test ();
T.say ("Li", "Wang");
Console.read ();
}
}
Class Test
{
int num = 0;
public void say (params string[] name)
{
foreach (string item in name)
{
Console.WriteLine (item);
}
}
}
Examples of Java mutable parameters:
public class Pram {
public static void Main (string[] args) {
Pram p = new Pram ();
P.say ("Li", "Wang");
}
public void Say (String ... name)
{
for (String n:name)
{
SYSTEM.OUT.PRINTLN (n);
}
}
}
As you can see from the example, C # is labeled as a variable parameter by the keyword params, and the type must be an array, and the variable parameter of Java is simply marked by the "..." three dots behind the type, and the variable parameters are internally treated with arrays. Therefore, the method of overloading variable parameters in Java and the immutable parameter array method of corresponding type can not form overloading.
Variable parameters for Java Foundation-java and C #