Go基础之枚举
Go语言不支持enum关键字
Go语言通常用const后跟圆括号定义一组常量的方式来实现枚举
代码示例:
package main import ( "fmt" ) const ( Sunday = iota Monday Tuesday Wednesday Thursday Friday Saturday numberOfDays ) func main(){ fmt.Println(Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,numberOfDays) }
说明:
1、以大写字母开头的常量在包外可见
2、numberOfDays则为包内私有