• go内建方法 make方法


    package main
    
    import "fmt"
    
    func main()  {
    
        // make函数
        makeSlice() // 创建切片
        makeMap() // 创建集合
        makeChan() // 创建channel
    }
    
    func makeSlice(){
        sl := make([]string,3)
        sl[0] = "a";
        sl[1] = "b";
        sl[2] = "c";
        fmt.Println(sl)
    
    }
    
    func makeMap(){
        mp  := make(map[int] string)
    
        mp[0] = "hello"
        mp[1] = "world"
        mp[33] = "!"
        fmt.Println(mp)
    }
    
    func makeChan()  {
        mchan := make(chan string)
    
        go func() {
            mchan <- "hello world"
        }()
    
        message := <- mchan
    
        fmt.Println(message)
    }
    GOROOT=/usr/local/go #gosetup
    GOPATH=/www/gopath #gosetup
    /usr/local/go/bin/go build -i -o /private/var/folders/fc/4txmmczj6q92p6058h3w7t_80000gn/T/___go_build_main_go__2_ /www/go/learn/main.go #gosetup
    /private/var/folders/fc/4txmmczj6q92p6058h3w7t_80000gn/T/___go_build_main_go__2_ #gosetup
    [a b c]
    map[0:hello 1:world 33:!]
    hello world
    
    Process finished with exit code 0
    

      

  • 相关阅读:
    PPP与资产证券化
    每日一题_190918
    每日一题_190917
    每日一题_190916
    每日一题_190915
    每日一题_190914
    每日一题_190913
    每日一题_190912
    每日一题_190911
    每日一题_190910
  • 原文地址:https://www.cnblogs.com/php-linux/p/13056185.html
Copyright © 2020-2023  润新知