File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ package map_
2+
3+ import "fmt"
4+
5+ func MapDelete () error {
6+
7+ var (
8+ f = func (v map [string ]int ) {
9+ fmt .Printf ("len: %d\t val: %v\n " , len (v ), v )
10+ }
11+
12+ m = map [string ]int {
13+ "a" : 100 ,
14+ "b" : 200 ,
15+ }
16+ )
17+
18+ f (m )
19+
20+ // map から要素を削除する場合 組み込み関数 delete() を使う
21+ delete (m , "a" )
22+
23+ f (m )
24+
25+ delete (m , "b" )
26+
27+ f (m )
28+
29+ // 存在しない要素を delete に渡してもエラーにはならない。何も起きないだけ。
30+ delete (m , "a" )
31+
32+ f (m )
33+
34+ return nil
35+ }
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ func (m SampleMapping) MakeMapping() {
4444 m ["map_basic" ] = map_ .MapBasic
4545 m ["map_for" ] = map_ .MapFor
4646 m ["map_initialize" ] = map_ .MapInitialize
47+ m ["map_delete" ] = map_ .MapDelete
4748 m ["scope01" ] = scope .Scope01
4849 m ["async01" ] = async .Async01
4950 m ["reflection01" ] = reflection .Reflection01
You can’t perform that action at this time.
0 commit comments