码迷,mamicode.com
首页 > 其他好文 > 详细

Golang枚举示例之Day

时间:2014-11-30 13:51:44      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   on   div   

GOPATH\src\day\day.go

package day

type Day uint

const (
    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 main

import "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)
}

 

输出:

bubuko.com,布布扣

 

Golang枚举示例之Day

标签:style   blog   http   io   ar   color   sp   on   div   

原文地址:http://www.cnblogs.com/CPyARM/p/4132987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!