【发布时间】:2017-12-21 00:38:54
【问题描述】:
我刚刚创建了这段代码来试验type,我稍后会解释问题。
我的代码:
package main
import (
"fmt"
"math/rand"
"time"
)
type Games struct {
game string
creator string
}
func main() {
videogames := []Games{
{"inFamous", "Sucker Punch Games"},
{"Halo", "343 Games"},
{"JustCause", "Eidos"},
}
rand.Seed(time.Now().UTC().UnixNano())
i := rand.Intn(len(videogames))
fmt.Print(videogames[i])
}
如果我运行它,结果将是,
{inFamous,Sucker Punch Games}
现在我要做的是分离数组,以便结果是,
Game = inFamous
Publisher = Sucker Punch Games
我还需要删除左括号和右括号。
【问题讨论】: