Varagrs, Array and parameter list

I have searched the forum but I am still unable to understand the following differences:

    1) void sum(5,5,5,6,7,8,9,3,5,3,2,3,6){}
    2) void sum(int[] i){}
    3) void sum(int... i){}

And if 3) can be treated as array then what about 1)?


void sum(5,5,5,6,7,8,9,3,5,3,2,3,6){} won't even compile because it is not a valid method declaration

A method parameter list in parenthesis should be a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses.

2 & 3 are basically the same thing except if you will call the method sum(5,5,5); it won't resolve to method void sum(int[] a ){} because this method is expecting an int array as an calle method argument whereas void sum(int... a){} will work fine as it is expecting variable number of int type arguments in method call.

2 and 3 are basically the same thing. 3 is more elegant because you dont have to create the array before calling the method. Java does that for you.

1 is useful if the number of arguments are never going to change.

Need Your Help

In PowerBuilder, can I use an object as part of my menu?

object menu menuitem powerbuilder

Is it possible with menus 4 layers deep to set up a link to another menu? If I made the menu 2 layers deep and then set the link at the end to another menu (or to an object), it would be easier to ...

Stop collection view filtering

c# wpf mvvm listbox observablecollection

I have two List boxes ,both has item source set as MyList.In listbox1 I want to filter the entries based on some predicate.I achieve that by following code