2 回答
TA贡献1847条经验 获得超7个赞
是的,可以使用枚举索引声明一个数组数组。
package main
import "fmt"
type (
Color int
Fruit int
)
const (
Red Color = 1
Blue Color = 2
NumColor = 3
Apple Fruit = 1
BlueBerry Fruit = 2
NumFruit = 3
)
func main() {
var produce [NumFruit][NumColor]string
produce[Red][Apple] = "Yummy Apple"
fmt.Printf("%#v\n", produce)
}
https://go.dev/play/p/AxwcxLE3iJX
TA贡献1815条经验 获得超6个赞
从声明中删除 MyType。然后它会起作用。
type (
Color int
Fruit int
)
const (
Red Color = 1
Blue Color = 2
Apple Fruit = 1
BlueBerry Fruit = 2
)
func DoIt() {
produce := make([][]string, 0)
produce[Red][Apple] = "Yummy Apple"
}
- 2 回答
- 0 关注
- 114 浏览
添加回答
举报