充电时间 Go中的数组、切片、map简单示例

数组是固定长度的,依稀让我想起了VB;切片是动态的;map一般是键值对

package main

import (
    "fmt"
)

func main() {

    var username string

    fmt.Println(username)

    username = "abc"

    fmt.Println(username)

    //array
    names := [2]string{"a", "b"}

    fmt.Println(names)

    //slice
    names2 := [...]string{1: "Jan", 2: "Feb"}
    fmt.Println(names2)

    //map
    ages := map[string]int{
        "jimmy": 31,
        "tom":   32,
    }
    ages["lily"] = 18

    fmt.Println(ages)

    ages["lucy"] += 10

    fmt.Println(ages)

}
上一篇:mobl:针对移动Web开发的DSL


下一篇:服务(Service)全解析(三)--IntentService