首页 > 其他 > 详细

go chapter 7 - 类型

时间:2018-08-02 15:36:35      阅读:151      评论:0      收藏:0      [点我收藏+]

任意类型

interface{}

 

遍历并判断类型

func MyPrintf(args ...interface{}) {
    for _, arg := range args {
        switch arg.(type) {
            case int:
                fmt.Println(arg, "is an int value.")
            case string:
                fmt.Println(arg, "is a string value.")
            case float64:
                fmt.Println(arg, "is an float64 value.")
            case bool:
                fmt.Println(arg, "is an bool value.")
            default:
                fmt.Println(arg, "is an unknown type.")
         }
    }
}

 

go chapter 7 - 类型

原文:https://www.cnblogs.com/webglcn/p/9407242.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!