I m currently working my way through the excellent Tour of Go. I finished one of the exercises (#45) with the following solution:
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
}
我不理解为什么我不得不使用<代码>make的声明>和uint8
。 两种类型(见刀切的评论)。 这似乎多余,但我无法说明如何以其他方式做到这一点。