zoukankan      html  css  js  c++  java
  • 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补:
    昨天看书看到这个叫类型断言
    表达式

  • 相关阅读:
    HDU-1205
    HDU-2033
    HDU-2032
    HDU-2031
    HDU-2030
    HDU-2029
    HDU-2028
    HDU-2027
    HDU-2026
    HDU-2025
  • 原文地址:https://www.cnblogs.com/adoontheway/p/9958555.html
Copyright © 2011-2022 走看看