【发布时间】:2018-11-15 00:43:12
【问题描述】:
package main
import (
"fmt"
)
func main() {
var result [][]int
var tempArr []int
tempArr = append(tempArr, 1, 2, 3, 5)
result = append(result, tempArr)
prepend := []int{1, 2, 3}
result = append([]int{prepend}, result...) // Not working
fmt.Println(result)
}
添加到数组的正确方法是什么?我需要帮助来修复这条线:
result = append([]int{prepend}, result...)
【问题讨论】:
-
在切片技巧 wiki 中的 push front 之后,代码应为:
result = append([][]int{prepend}, result...) -
我通过这样做
result = append([][]int{prepend}, result...)得到了这个工作
标签: go