我目前正在努力通过优秀的Tour of Go名. 我用以下解决方案完成了其中一个练习(#45):
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy) /* type declaration */
for i := range pic {
pic[i] = make([]uint8, dx) /* again the type? */
for j := range pic[i] {
pic[i][j] = uint8((i+j)/2)
}
}
return pic
}
我不明白为什么我必须对uint8
类型使用两次make
语句(参见代码片段中的注释).这似乎是多余的,但我想不出用其他方法做这件事.