go 定义枚举值

go没有枚举类型,可以通过iota来定义枚举值。

package main

import "fmt"

type Status int

const (
	Unknown Status = iota
	Success
	Fail
)

func main() {
	// 输出1
	fmt.Println(Success)
}

 

posted on 2026-04-05 09:11  王景迁  阅读(7)  评论(0)    收藏  举报

导航