Go map is simple and practical

// MapFunc01 ... Map using 
FUNC MapFunc01 () {
     // Map need to make allocation of space, to use 
    var M1 Map [ String ] String 
    M1 = make (Map [ String ] String , 10 ) 
    M1 [ " 11111 " ] = " insects " 
    M1 [ " 22222 " ] = " Brassica " 
    M1 [ " 33333 " ] = " small wind " 
    fmt.Println ( " M1 = " ,m1) 

    //Type inference 
    M2: = the make (Map [ String ] String , 10 ) 
    M2 [ " 11111 " ] = " insects " 
    M2 [ " 22222 " ] = " Brassica " 
    M2 [ " 33333 " ] = " small wind " 
    FMT. println ( " M2 = " , M2) 

    // type inference, initialization 
    M3: = Map [ String ] String {
         " 11111 " : "Small insects",
        "22222": "小白菜",
        "33333": "小东风",
    }
    fmt.Println("m3=", m3)
}

operation result

 

Guess you like

Origin www.cnblogs.com/xuqiulin/p/12348165.html