List.FindAll不返回结果集

时间:2013-10-11 12:04:13

标签: vb.net linq

我有下一个代码。我正在从一个文本文件中读取,创建一个记录列表(我的结构)。 接下来,我需要从列表中获取所有记录对象,其中团队名称等于表单上文本框中的团队名称

Public Class Form1

    Structure Record

        Sub New(ByVal arr As String())
            Me.team = arr(0)
            Me.player = arr(1)
            Me.bats = CInt(arr(2))
            Me.hits = CInt(arr(3))
        End Sub
        Dim team As String
        Dim player As String
        Dim bats As Integer
        Dim hits As Integer
    End Structure

    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        Dim team As String = txtTeam.Text
        Dim records As New List(Of Record)

        records.AddRange(
            From line In IO.File.ReadAllLines("Baseball.txt")
            Select New Record(line.Split(","c))
            )

        records = records.FindAll(Function(record) record.team.Equals(team))

        Dim a As Integer = 1
        a += 1

    End Sub
End Class

问题是我在

之后收到了0条记录
records = records.FindAll(Function(record) record.team.Equals(team))

有什么建议吗?

P.S:这是断点

Dim a As Integer = 1
a += 1

1 个答案:

答案 0 :(得分:1)

问题解决了,我是个白痴:)

Structure Record
    Sub New(ByVal arr As String())
        Me.player = arr(0)
        Me.team = arr(1)
        Me.bats = CInt(arr(2))
        Me.hits = CInt(arr(3))
    End Sub
    Dim team As String
    Dim player As String
    Dim bats As Integer
    Dim hits As Integer
End Structure

我的结构出错了。将前两个字段混为一谈。 感谢所有