您可以使用该Enumerable.Range
方法创建一个单维数组,如下所示:
Dim start = 0
Dim count = 10
Dim singleArray = Enumerable.Range(start, count).ToArray()
要创建多维数组,您必须创建自己的扩展方法来修改集合,如下所示
Public Module Extensions
<Runtime.CompilerServices.Extension()>
Function SelectMultiDimension(Of T)(collection As IEnumerable(Of T), rows As Integer, cols As Integer) As T(,)
Dim multiDimArray(rows - 1, cols - 1) As T
Dim i As Integer = 0
For Each item In collection
If i >= multiDimArray.Length Then Exit For
multiDimArray(i \ cols, i Mod cols) = item
i += 1
Next
Return multiDimArray
End Function
End Module
然后你可以这样使用它:
Dim mArray = Enumerable.Range(start, count).SelectMultiDimension(3, 4)