您的位置:首页 > 编程语言 > Go语言

A Tour of Go Maps

2014-10-27 22:51 295 查看
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"])
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: