我想為二維數組分配空間,我想以一種干凈的方式這樣做。address [10]intmyLength := len(address)// 1. but this not work at allmatrix := [myLength][myLength]byte// 2. and this initializes 10 arrays with length 0matrix := make([][]int, myLength, myLength)第一次嘗試時出現錯誤:非常量數組綁定 l
1 回答

幕布斯7119047
TA貢獻1794條經驗 獲得超8個贊
沒有“一個班輪”的方式來做到這一點。只需這樣做:
matrix := make([][]int, myLength)
for i : = 0; i < myLength; i++ {
matrix[i] = make([]int, myLength)
}
- 1 回答
- 0 關注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消