golang .(type)語法

一直弄不懂 .(type) 是啥,在 liteide 中輸出 (1+1).(type),提示:

use of .(type) outside type switch

於是搜索到這個文章:

作者:翔雲翔雲
來源:CSDN
原文:https://blog.csdn.net/lanyang123456/article/details/78070886
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

package main

import (
        "fmt"
)


func main() {

 CheckType("tow", 88, "three")

}



func CheckType(args ...interface{}) {


        for _,v := range args {

                switch v.(type) {

                        case int:

                                fmt.Println("type:int, value:", v)
                        case string:
                                fmt.Println("type:string, value:", v)

                        default:

                                fmt.Println("type:unkown,value:",v)


                }

        }


}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章