You were almost there, here is an example:
(您快到了,这里有个例子:)
package main
import (
"fmt"
)
func myFunc(arr []int) {
fmt.Println(arr)
}
func main() {
var arr = []int{1, 2, 3, 54, 3}
myFunc(arr)
}
Live on playground
(住在操场上)
PS As @torek mentioned, to be precise, you are using a slice not an array.
(PS如@torek所述,确切地说,您使用的是切片而不是数组。)
Arrays have constant length and cannot grow, and the function signature for array in my example would be myFunc(arr [5]int)
. (数组具有恒定的长度并且不能增长,在我的示例中,数组的函数签名为myFunc(arr [5]int)
。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…