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)


                }

        }


}

2019/01/02補:
昨天看書看到這個叫類型斷言
表達式


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM