新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Golang常量iota的使用實例
Codes

為偏關(guān)等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務,及偏關(guān)網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務為成都網(wǎng)站制作、網(wǎng)站設(shè)計、偏關(guān)網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
package main
import "fmt"
type color byte
const (
black color = iota
red
blue
)
func test(c color) {
fmt.Println(c)
}
func main() {
const (
x = iota // 0
y // 1
z // 2
)
fmt.Printf("x=%v, y=%v, z=%v\n", x, y, z)
const (
_ = iota
KB = 1 << (10 * iota) // 1 << (10 * 1)
MB // 1 << (10 * 2)
GB // 1 << (10 * 3)
)
fmt.Printf("KB=%v, MB=%v, GB=%v\n", KB, MB, GB)
const (
_, _ = iota, iota * 10 // 0, 0 * 10
aa, bb // 1, 1 * 10
cc, dd // 2, 2 * 10
)
fmt.Printf("aa=%v, bb=%v, cc=%v, dd=%v\n", aa, bb, cc, dd)
const (
a = iota // 0
b // 1
c = 100 // 100
d // 100
e = iota // 4
f // 5
)
fmt.Printf("a=%v, b=%v, c=%v, d=%v, e=%v, f=%v\n", a, b, c, d, e, f)
const (
g = iota // 0
h float32 = iota // 1
i = iota // 2
)
fmt.Printf("g: %T %v, f: %T %v, h: %T %v\n", g, g, h, h, i, i)
test(black) // 0
test(red) // 1
test(blue) // 2
test(100) // 100 并未超出 color/byte 類型取值范圍
// xx := 2
// test(xx)
}Result
x=0, y=1, z=2
KB=1024, MB=1048576, GB=1073741824
aa=1, bb=10, cc=2, dd=20
a=0, b=1, c=100, d=100, e=4, f=5
g: int 0, f: float32 1, h: int 2
0
1
2
100
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對創(chuàng)新互聯(lián)的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
本文題目:Golang常量iota的使用實例
文章地址:http://fisionsoft.com.cn/article/ighjhd.html


咨詢
建站咨詢
