我想在 Go 中定义一个二维数组或切片,并使用枚举值来访问数组中的数据。以下将不会编译,我希望你能帮助我弄清楚如何让它工作。
type (
Color int
Fruit int
MyType [][]string
)
const (
Red Color = 1
Blue Color = 2
Apple Fruit = 1
BlueBerry Fruit = 2
)
func DoIt() {
produce := make([][]MyType, 0)
// COMPILE ERROR: "Yummy Apple"' (type string) cannot be represented by the type MyType
produce[Red][Apple] = "Yummy Apple"
}
aluckdog
红糖糍粑
相关分类