码迷,mamicode.com
首页 > 其他好文 > 详细

Golang的iota的特性

时间:2016-09-07 14:37:07      阅读:433      评论:0      收藏:0      [点我收藏+]

标签:

Golang的iota的特性:

1. iota在每个ConstBlock中自动归0.

2. iota在每个ConstSpec后自动增1.

换言之: iota是ConstBlock中ConstSpec的下标.

例如:

const (

item0 = 1

item1 = 1

item2 = 1

item3 = 1

item4 = 1

item5 = 1

item6 = iota

)
func main() { fmt.Println(item0, item1, item5, item6)}
输出结果:

1 1 1 6

可见, iota就是ConstBlock中ConstSpec的下标. 所以item6的值是6, 而不是0.

Golang的iota的特性

标签:

原文地址:http://www.cnblogs.com/zolo/p/5849135.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!