Vararg don't take an array?

If I have:

fun sum(vararg numbers : Double) = numbers.sum()

I can only call:

sum(1,2,3)

I can’t call:

sum(arrayOf(1,2,3))

Why not??

In C# if I have:

int sum(params int list)

I can pass:

sum(1,2,3)

or

sum(new int{1,2,3})

sum(*arrayOf(1,2,3))

1 Like

And to add to the response of Raman, this is called the spread operator and is documented here https://kotlinlang.org/docs/reference/functions.html#variable-number-of-arguments-varargs

2 Likes