Variable parameters for Java Foundation-java and C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.