A Tour of Go Maps

时间:2014-10-28 00:18:07   收藏:0   阅读:184

A map maps keys to values.

Maps must be created with make (not new) before use; the nil map is empty and cannot be assigned to.

package main 

import "fmt"

type Vertex struct{
    Lat, Long float64
}

var m map[string]Vertex

func main() {
    m = make(map[string]Vertex)
    m["Bell Labs"] = Vertex{
        40.68433, -74.39967,
    }
    fmt.Println(m["Bell Labs"])
}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!