Golang 使用const定义枚举

    技术2025-10-22  17

    package main import ( "fmt" ) // 使用const 来定义一个Color的枚举 type Color int const ( RED Color = iota BLACK ) type Tree struct { Data int //数据 Color Color //颜色 } func main() { t1 := rbtree.Tree{1,RED} fmt.Println(t1) } //{1 0}
    Processed: 0.009, SQL: 9