3 ms·
Arrays in Go
- Laremere 12y agoThe []int{1,2,3} method for initializing slices was missed: http://play.golang.org/p/FEXc1sxVLK http://play.golang.org/p/FEXc1sxVLK
- tshadwell 12y agoI've been using a pattern like this for my more complex initialisations: s, i := make([]T, 0, 6), 0 s = append(s, 1, 2, 3) //[1 2 3] fmt.Println(s[i:]) i += 3 s = append(s, 4, 5, 6) //[4 5 6] fmt.Println(s[i:]) i += 3 // [etc...] //[1 2 3 4 5 6] fmt.Println(s[:]) You can easily make references to each chunk of the slice you append without much difficulty or any re-sizing (the first s[:] will remain a slice of the first 3 items).