通过LINQ列出数组

时间:2013-05-09 10:15:07

标签: vb.net linq

我已经对此进行了很好的研究,但我仍然非常不确定,有人可以告诉我如何将其优化为LINQ吗?这看起来有点旧,我确信有一种方法可以使用LINQ。

Dim existingSpends(Spend.Count, 4) As Double
Dim row As Integer, col As Integer
row = 0
For Each s As MarketingSpend_Chart In Spend
    existingSpends(row, 0) = s.field1
    existingSpends(row, 1) = s.field2
    existingSpends(row, 2) = s.field3
    existingSpends(row, 3) = s.field4
    row += 1
Next

1 个答案:

答案 0 :(得分:0)

Linq旨在生成实现IEnumerable的结果,例如List和一维数组。我还没有看到可以创建二维数组的linq方法。

但是,如果您想更改结果集,则可以使用锯齿状数组

MarketingSpend_Chart.Select(Function(s) New Double(4) {s.field1, _
                                                       s.field2, _
                                                       s.field3, _
                                                       s.field4}) _
                    .ToArray()

我同意这些评论,但Linq在这里是不必要的。