将整数转换为枚举值

时间:2017-10-27 11:56:12

标签: go

我有以下代码:

type ActorState int

const (
    Unverified ActorState = 1 + iota
    Verified
    Banned
)

我想在我的实施中这样做。

i := 1
a : ActorState 
a = ActorState(i)

但我收到错误Cannot convert expression of type int, error to type ActorState

我如何转换呢?

1 个答案:

答案 0 :(得分:8)

你的语法错了,你的意思是

i := 1
a := ActorState(i)

i := 1
var a = ActorState(i)

i := 1
var a ActorState
a = ActorState(i)
相关问题