草庐IT

enums - 从 Go 中的一组相关常量创建一个枚举

在Go语言中对大量相关常量进行分组的首选(或正确)方法是什么?例如C#和C++都有enum。 最佳答案 const?const(pi=3.14foo=42bar="hello") 关于enums-从Go中的一组相关常量创建一个枚举,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6937716/

enums - 在 Go 中表示枚举的惯用方式是什么?

我试图表示一个简化的染色体,它由N个碱基组成,每个碱基只能是{A,C,T,G}之一。我想用枚举形式化约束,但我想知道在Go中模拟枚举最惯用的方式是什么。 最佳答案 引用语言规范:IotaWithinaconstantdeclaration,thepredeclaredidentifieriotarepresentssuccessiveuntypedintegerconstants.Itisresetto0wheneverthereservedwordconstappearsinthesourceandincrementsaftere