feat(Go-StudyExample):包方法重构

This commit is contained in:
Huangzj
2020-12-16 11:30:31 +08:00
parent 1d21a9634e
commit a97c2c9bcc
17 changed files with 74 additions and 125 deletions
+42
View File
@@ -0,0 +1,42 @@
/*
* @Author : huangzj
* @Time : 2020/7/13 14:22
* @Description
*/
package originGoLanguage
import (
"fmt"
"testing"
)
func TestMap(t *testing.T) {
//没有初始化的是nil,不能进行赋值
var countryMap1 map[string]string
fmt.Println(countryMap1 == nil)
countryMap := make(map[string]string)
countryMap["a"] = "aCountry"
countryMap["b"] = "bCountry"
countryMap["c"] = "cCountry"
countryMap["d"] = "dCountry"
for key, value := range countryMap {
fmt.Println(key + " is " + value)
}
//获取Map的值
mValue, ok := countryMap["a"]
fmt.Println(ok, mValue)
mValue1, ok1 := countryMap["aaaa"]
fmt.Println(ok1, mValue1)
//删除map中的元素
delete(countryMap, "a")
delete(countryMap, "b")
for key, value := range countryMap {
fmt.Println(key + " is " + value)
}
}