如下例子,若要改变aa["1"]中Gi的值,只能:先读出AA结构的值---改变AA的某个字段---赋值给aa["1"]吗?
```go
package main
import (
"fmt"
)
type AA struct {
Gi int
Gs string
}
func main() {
aa := make(map[string]AA)
aa["1"] = AA{1, "1"}
if v, ok := aa["1"]; ok {
v.Gi = 2
aa["1"] = v
}
fmt.Printf("%+v\n", aa)
}
```
更多评论
感谢指教,已验证可以。
```go
package main
import (
"fmt"
)
type AA struct {
Gi int
Gs string
}
func main() {
aa := make(map[string]AA)
aa["1"] = AA{1, "1"}
if v, ok := aa["1"]; ok {
v.Gi = 2
aa["1"] = v
}
fmt.Printf("%+v\n", aa)
bb := make(map[string]*AA)
bb["2"] = &AA{2, "2"}
bb["2"].Gi = 3
for k, v := range bb {
fmt.Printf("%v:%+v\n", k, v)
}
}
```
#2