Yeah, not sure which is better, Java's or C#'s varargs, but it does make
things nicer at times. In C#, the method signature signature screams "I AM
passing an array", but you can pass arguments either way as in Java.
C#:
----------------
public void UseVarargs(params int[] args)
{
// Do something using argument array
}
public static void Main()
{
UseVarargs(1);
UseVarargs(1, 2, 3);
UseVarargs(new int[3] {1, 2, 3});
}
C#:
----------------
public void UseVarargs(params int[] args)
{
// Do something using argument array
}
public static void Main()
{
UseVarargs(1);
UseVarargs(1, 2, 3);
UseVarargs(new int[] {1, 2, 3});
}
Java:
----------------
public void useVarargs(int... args) {
// Do something using argument array
}
public static void main(string [] args) {
useVarargs(1);
useVarargs(1, 2, 3);
useVarargs(new int[] {1, 2, 3});
}
On Fri, Jun 17, 2011 at 1:35 PM, Gregg Reynolds <[email protected]> wrote:
> On Fri, Jun 17, 2011 at 10:17 AM, Mark Rathwell <[email protected]>
> wrote:
> >
> > In Java, varargs are actually converted to arrays at compile time. It is
> > really just some syntactic sugar allowing you to use nicer syntax for
> array
> > arguments, and you can pass the arguments as an array, or as a comma
> > delimited sequence of arguments.
>
> Right, but the problem is when you pass just one thing (or nothing).
> It may get converted, but the syntax of the call declares loudly "I am
> NOT passing an array". Atrocious language design, IMO, and it cost me
> several frustrating and wasted hours. A minor point but good for a
> cheat sheet.
>
> -Gregg
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en