首先itoa 是什么
const 内的 iota是golang语言的常量计数器,只能在常量的表达式中使用,,即const内。
iota在const关键字出现时将被重置为0(const内部的第一行之前),const中每新增一行常量声明将使iota计数一次。
可以参照行号理解,也就是说将iota理解为const语句块中的行索引。
关于其特性举例如下:
通过例子说明其各种特性。
1、每次 const 出现时,都会让 iota 初始化为0.
const a = iota // a=0
const (
b = iota //b=0
c //c=1
)
2、自定义类型
自增长常量经常包含一个自定义枚举类型,允许你依靠编译器完成自增设置。
type Newtype int
const (
T1 Newtype = iota // 0
T2 // 1
T3 // 2
T4 // 3
)
3、可跳过的值
type AudioOutput int
const (
OutMute AudioOutput = iota // 0
OutMono // 1
OutStereo // 2
_