当前位置:网站首页>[golang] quick review guide quickreview (III) - Map
[golang] quick review guide quickreview (III) - Map
2022-06-23 20:22:00 【DDGarfield】
A scientific name : Mapping relation container .
Common name : Key value pair key-value
map Follow slice equally , It is still a reference type .
map
1.C# Dictionary in
according to map Characteristics , The blogger's analogy is C# Chinese Dictionary Dictionary, Are also key value pairs .
// Definition initialization
Dictionary<int, string> dic = new Dictionary<int, string>
{
{1," Student "},
{2," teacher "},
{3," Parent "}
};
// newly added
dic.Add(4, " The headmaster ");
// Judge whether it contains key
if (dic.ContainsKey(1))
{
}
// Judge whether it contains value
if (dic.ContainsValue(" Student ")) { }
// Ergodic dictionary
foreach (KeyValuePair<int, string> kv in dic)
{
}
// Delete the specified key The elements of
dic.Remove(1);
// Empty dictionary
dic.Clear();
2.Golang Medium map
2.1 Definition initialization
make(map[KeyType]ValueType, [cap]),cap Optional
testMap := make(map[int]string, 3)
testMap[1] = " Student "
testMap[2] = " teacher "
testMap[3] = " Parent "
fmt.Println(testMap)
map[1: Student 2: teacher 3: Parent ]
2.2 Traverse
Use for k,v:=range map{} Traverse :
// Traverse
for k, v := range testMap {
fmt.Println(k, v)
}
1 Student
2 teacher
3 Parent
2.3 Delete
Delete , Use built-in functions delete()
func delete(m map[Key]Type, key Key)
// Delete
delete(testMap, 1)
for k, v := range testMap {
fmt.Println(k, v)
}
3 Parent
2 teacher
2.4 The key is coming.
Slice is a type , And used frequently , Slicing can also be used as map Value value
var mapValueSlice = make(map[string][]string, 3)
var sc []string
sc = append(sc, " Chengdu ", " mianyang ", " Yibin ")
var sx = []string{" Xi'an ", " Hanzhong city ", " Yulin "}
mapValueSlice[" sichuan "] = sc
mapValueSlice[" shaanxi "] = sx
fmt.Println(mapValueSlice)
map[ sichuan :[ Chengdu mianyang Yibin ] shaanxi :[ Xi'an Hanzhong city Yulin ]]
One last word ,golang To understand the source code, you need to have a solid basic syntax , The following function , Method recipient , The pointer , Parameters , Return value , Channels and so on , Look from a distance , brackets [] Flying across ,*, In fact, all changes can't be separated from their ancestors , These basic types are combined according to semantics .
Again : This series is not a tutorial , If you want to learn systematically , Bloggers can recommend learning resources .
边栏推荐
- Kotlin jetpack compose Tab的渲染 AnimatedVisibility的使用
- Application de JDBC dans les essais de performance
- 【Golang】快速复习指南QuickReview(三)——map
- Development of block hash quiz game system (DAPP)
- Tcp/udp Fundamentals
- Rstudio 1.4 software installation package and installation tutorial
- 硬件开发笔记(六): 硬件开发基本流程,制作一个USB转RS232的模块(五):创建USB封装库并关联原理图元器件
- The "open source star picking program" container pulls private images from harbor, which is a necessary skill for cloud native advanced technology
- Is Huishang futures trading software formal? How to download safely?
- What are the requirements for new bonds? Is it safe to play new bonds
猜你喜欢

「开源摘星计划」Containerd拉取Harbor中的私有镜像,云原生进阶必备技能

The evolution of the "Rainbow Bridge" middleware platform for the acquisition database based on shardingsphere

SAVE: 软件分析验证和测试平台

20 provinces and cities announce the road map of the meta universe

如何避免基因领域“黑天鹅”事件:一场预防性“召回”背后的安全保卫战

Kubernetes 资源拓扑感知调度优化

Rendering of kotlin jetpack compose tab using animatedvisibility

基于SSM实现微博系统

Live sharing | Tencent cloud mongodb intelligent diagnosis and Performance Optimization Practice

Hotline salon issue 26 - cloud security session
随机推荐
UST 崩盘后,稳定币市场格局将迎来新机遇?
Official announcement. Net 7 preview 5
OHOS LTS 3.0移植到RaspberryPi 4B
@@Script implementation of ishell automatic deployment
Kinsoku jikou desu新浪股票接口变动
Development of block hash quiz game system (DAPP)
「开源摘星计划」Containerd拉取Harbor中的私有镜像,云原生进阶必备技能
[golang] quick review guide quickreview (VII) -- Interface
Elastricearch's fragmentation principle of the second bullet
Emmet语法规范
活动报名 | MongoDB 5.0 时序存储特性介绍
ZABBIX monitoring - Aruba AP operation data
Kubernetes 资源拓扑感知调度优化
基于SSM实现微博系统
Hardware development notes (6): basic process of hardware development, making a USB to RS232 module (5): creating USB package library and associating principle graphic devices
【Golang】深究字符串——从byte rune string到Unicode与UTF-8
5 月最大的 GameFi 崩溃受害者能否在熊市中生存?| May Monthly Report
MySQL时间函数的运用,简单问题
JDBC 在性能測試中的應用
Syntaxe des requêtes fédérées SQL (inline, left, right, full)