如果可以使用列表列表而不是数组列表,则可以这样做:
Private Function LoadFile(ByVal filePath As String) As List(Of List(Of Double))
Dim records As New List(Of List(Of Double))()
For Each line As String In File.ReadAllLines(filePath)
Dim values As New List(Of Double)()
For Each field As String In line.Split(New String() {ControlChars.Tab}, StringSplitOptions.None)
values.Add(Double.Parse(field))
Next
records.Add(values)
Next
Return records
End Function
或者,如果它必须是数组列表,您可以这样做:
Private Function LoadFileToArrays(ByVal filePath As String) As List(Of Double())
Dim records As New List(Of Double())()
For Each line As String In File.ReadAllLines(filePath)
Dim values As New List(Of Double)()
For Each field As String In line.Split(New String() {ControlChars.Tab}, StringSplitOptions.None)
values.Add(Double.Parse(field))
Next
records.Add(values.ToArray())
Next
Return records
End Function
如果您需要一个数组数组,records.ToArray()
则可以在最后一个示例中返回。我没有添加任何代码来处理无效或空字段值,因为在您的问题中不清楚您将如何处理这些值。因此,您需要添加代码以适当地处理该问题,否则,此代码将在这种情况下引发异常。