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 關注
- 150 瀏覽
添加回答
舉報