Go: Define multidimensional array with existing array's type and values?
arrays, go, multidimensional-array
Solution
The following code would also work. Both your example and mine do the same thing and neither should be much faster than the other.
Unless you use reflect to make a slice (not array) of your `[3]int`, it is impossible to not repeat `[3]int` in your new type. Even that is not possible in the current release. It is in tip and will be released in Go 1.1.
package main
import "fmt"
func main() {
a := [...]int{4,5,6}
var b = [2][3]int{a, a}
fmt.Println(b)
}
Problem
Is it possible to a)define b)initialize a new multidimensional array using an existing array, like in following code instead of `var b [2][3]int`, just saying something like `var b [2]a` ? Using a's type whatever it is, instead of hardcoding it (which misses the point of using [...] for a). And perhaps handling initialization=copying of values at the same time? ``` package main func main () { a := [...]int{4,5,6} var b [2][3]int b[0],b[1] = a,a } ``` (I'm aware of ease and convenience of slices, but this question is about understanding arrays.) Edit: can't believe I forgot about `var b [2][len(a)]int`, beginner's brain freeze. One line answer would be `var b = [2][len(a)]int{a,a}` . That's a type conversion, right?