🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
Go语言现阶段没有枚举类型,但是可以使用 const 常量配合上一节《Go语言常量》中介绍的 iota 来模拟枚举类型。 ~~~ type Weapon int const ( Arrow Weapon = iota // 开始生成枚举值, 默认为0 Shuriken SniperRifle Rifle Blower ) // 输出所有枚举值 fmt.Println(Arrow, Shuriken, SniperRifle, Rifle, Blower) // 使用枚举类型并赋初值 var weapon Weapon = Blower fmt.Println(weapon) ~~~ 输出如下: ~~~ 0 1 2 3 4 4 ~~~