-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map声明和初始化 #6
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
声明
map类型的变量声明方式如下:
比如:
在声明的时候不需要知道 map 的长度,map 是可以动态增长的。map 是引用类型,所以未初始化的 map 的zero value是 nil。nil map没有键也不能向其添加键(写入nil map会引发允许时错误:
panic: assignment to entry in nil map
)初始化
map 是引用类型 ,内存用 make 方法来分配,如下三种方式是等效的
mapAssigned
是mapLit
的引用,对mapAssigned
的修改也会影响到 mapLit 的值。mapLit
的初始话说明了map literals
的使用方法:map
可以用{key1: val1, key2: val2}
的描述方法来初始化,就像数组和结构体一样。The text was updated successfully, but these errors were encountered: