<3> go 枚举
2015-11-19 18:14
513 查看
在go语言中,没有直接支持枚举的关键字,也就造成go没有直接枚举的功能。但是go提供另一种方法来实现枚举,那就是const+iota
[code]// 实现枚举例子 type State int // iota 初始化后会自动递增 const ( Running State = iota // value --> 0 Stopped // value --> 1 Rebooting // value --> 2 Terminated // value --> 3 ) func (this State) String() string { switch this { case Running: return "Running" case Stopped: return "Stopped" default: return "Unknow" } } func main() { state := Stopped fmt.Println("state", state) } // 输出 state Running // 没有重载String函数的情况下则输出 state 0
相关文章推荐
- cpongo
- django template 自定义filter的使用
- Mongoose6.0源码分析(3)-重要结构体
- golang 大文件分割
- Google breakpad
- Django里,如何更改ADMIN管理后台的显示
- 揭秘TensorFlow:Google开源到底开的是什么?
- ubuntu下Django的安装和使用(一)
- GO语言实现文件上传
- Django学习笔记2
- 【Educational Codeforces Round 1D】【DFS 联通块打标记法】Igor In the Museum 联通块内墙的面数
- GO语言的"类"操作
- go 读取文件, 最后有没有换行符
- control_msgs/FollowJointTrajectoryActionGoal Message
- 有了 Mesos,Verizon 终于不用再羡慕 Google 了
- compiler dragonbook
- 学习golang并做一个简单分布式存储项目
- 谷歌验证 (Google Authenticator) 的实现原理是什么?
- <2> go -反射-函数map化
- 【推荐算法概览】《Overview of Recommender Algorithms》