首页 > 代码库 > Golang枚举示例之Day
Golang枚举示例之Day
GOPATH\src\day\day.go
package daytype Day uintconst ( Sunday Day = iota Monday Tuseday Wednesday Thursday Friday Saturday)func (day Day) String() string { switch day { case Sunday: return "Sunday" case Monday: return "Monday" case Tuseday: return "Tuesday" case Wednesday: return "Wednesday" case Friday: return "Friday" case Saturday: return "Saturday" default: return "Invalid" }}
main.go
package mainimport "fmt"import "day"func main() { var today day.Day today = day.Sunday tomorrow := day.Monday fmt.Println("today: ", today) fmt.Println("tomorrow: ", tomorrow) fmt.Printf("type of today: %T\n", today) fmt.Printf("type of tomorrow: %T\n", tomorrow)}
输出:
Golang枚举示例之Day
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。