这是我想做的
for _,p := range *players {
for _,tp := range *tournamentPlayers{
if p.Id==tp.PlayerId {
p.Points += tp.Prize
}
}
}
白白得救之后
最佳答案
当您对数组进行范围
时,第二个变量将是该值的副本。因此,当您修改它时,实际上并没有修改存储在数组中的值。
你需要使用索引:
for i := range *players {
for _,tp := range *tournamentPlayers{
if players[i].Id==tp.PlayerId {
players[i].Points += tp.Prize
}
}
}
您可以在 spec 中找到更多信息.
关于go - 如何更改go数组中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49681788/