Create list of list in go language

huangapple go评论83阅读模式
英文:

Create list of list in go language

问题

你好,我会帮你翻译以下内容:

嗨,我试图创建一个长度不确定的 SyntaxCommand 的切片的切片。

var result = make([][]SyntaxCommand)
result = append(result, []SyntaxCommand{})
temp := SyntaxCommand{}
result = append(result[len(result)-1], temp)

但是我遇到了错误:

missing len argument to make([][]SyntaxCommand)
temp = SyntaxCommand{}

如何轻松地创建一个可为空的对象的列表的列表?然后将新的列表添加到末尾,并在最后一个列表中添加一个长度不确定的对象?

英文:

Hi I try to create slice of slice of SyntaxCommand with undetermine length

var result = make([][]SyntaxCommand)
result = append(result, []SyntaxCommand{})
temp := SyntaxCommand{}
result = append(result[len(result)-1], temp)

but i encounter error

missing len argument to make([][]SyntaxCommand)
temp = SyntaxCommand{}

How to easily make a list of list of object that is nullable? Then add new list to the end, and an object to the last list with non undetermined length?

答案1

得分: 3

如果你不想初始化切片,就不要使用make

var result [][]SyntaxCommand
英文:

If you don't want to initialize the slice, don't use make

var result [][]SyntaxCommand

huangapple
  • 本文由 发表于 2017年6月12日 22:16:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/44501660.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定