go語言學習-iota

鏈客,專爲開發者而生,有問必答!區塊鏈

此文章來自[區塊鏈技術社區](https://www.liankexing.com),未經容許拒絕轉載。spa

14844519-e3576634ff1cbc1a.png

Go沒有枚舉類型,能夠用常量模擬能夠用iota生成從0 開始的自動增加的枚舉值。按行遞增,能夠省略後續行的 iota 關鍵字.code

iota 在一個const()中每次累加1,在不一樣const()中從新賦值爲0開始
const (three

Sundy = iota
Monday
Tuesday

)
/Sunday= 0 Monday= 1 Tuesday= 2/
在一個const中itoa 繼續累加開發

const (
A1 = iota //0
A2
str = "Hello" //獨立值
s //沒有賦值,跟上一行同樣,要想恢復自增,需再次賦值 iota
A3 = iota
A4
)
/A1= 0 A2= 1 str= Hello s= Hello A3= 4 A4= 5/
不一樣const從新賦值get

const (it

Sundy = iota
Monday
Tuesday

)
/Sunday= 0 Monday= 1 Tuesday= 2/io

const (社區

one = iota
two
three

)
/one= 0 two= 1 three= 2/class

相關文章
相關標籤/搜索