1 Star 0 Fork 0

liming/go-study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
map1.go 571 Bytes
一键复制 编辑 原始数据 按行查看 历史
liming 提交于 2023-11-06 09:15 +08:00 . 2023.11.3
package main
import "fmt"
type PersonInfo struct {
ID string
Name string
Address string
}
func main() {
var personDB map[string]PersonInfo
//声明
personDB = make(map[string]PersonInfo)
//map函数创建新map
personDB["12345"] = PersonInfo{"12345", "TOM", "Room 203..."}
personDB["1"] = PersonInfo{"1", "Jack", "Room 201..."}
//插入数据
person, ok := personDB["12345"]
//从map中查找键为"1234"的信息
if ok {
fmt.Println("Found people", person.Name, "with ID 12345")
} else {
fmt.Println("Can't found people with ID 12345")
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/liming0523/go-study.git
git@gitee.com:liming0523/go-study.git
liming0523
go-study
go-study
master

搜索帮助