在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、iota (在常量的时候,当成枚举使用) 示例1 package main import "fmt" func main() { //1、iota常量自动生成器,每个一行,自动累加1 //2、iota给常量赋值使用 const ( a = iota b = iota c = iota ) fmt.Printf("a = %d, b = %d, c = %d\n", a, b, c) //3、iota遇到const,重置为0 const d = iota fmt.Printf("d = %d\n", d) } #执行结果 a = 0, b = 1, c = 2 d = 0
示例2: package main import "fmt" func main() { //1、iota常量自动生成器,每个一行,自动累加1 //2、iota给常量赋值使用 const ( a1 = iota //0 b1 c1 ) fmt.Printf("a1 = %d, b1 = %d, c1 = %d\n", a1, b1, c1) } #执行结果 a1 = 0, b1 = 1, c1 = 2
示例3 package main import "fmt" func main() { //1、iota常量自动生成器,每个一行,自动累加1 //2、iota给常量赋值使用 const ( i = iota j1, j2, j3 = iota, iota, iota k = iota ) fmt.Printf("i = %d, j1 = %d, j2 = %d, j3 = %d, k = %d\n", i, j1, j2, j3, k) } #执行结果 i = 0, j1 = 1, j2 = 1, j3 = 1, k = 2
|
请发表评论