写这个的更好方法是:增长数组

Gor*_*onB 0 vb.net arrays loops

之前正在查看一些代码,并且我认为必须有更优雅的方式来编写这个....

(returnVar.Warnings是一个字符串数组,它可以以任何大小返回,具体取决于记录的警告数)

For Each item In items
  If o.ImageContent.ImageId = 0 Then
    ReDim Preserve returnVar.Warnings(returnVar.Warnings.GetUpperBound(0) + 1)
    returnVar.Warnings(returnVar.Warnings.GetUpperBound(0)) = "Section: " & section.<header>.<title>.ToString & " , Item: " & item.<title>.ToString
  End If
Next
Run Code Online (Sandbox Code Playgroud)

Jas*_*son 7

使用通用List(字符串)然后获取包含列表数据的数组(如果需要)

dim list = new List(of string)
list.Add("foo")
list.Add("bar")
list.ToArray()
Run Code Online (Sandbox Code Playgroud)