Dim objLab As New ArrayList
objLab有300个名称列表,我想选择名称是否为Telkom,但返回空记录。我试图在运气不好的情况下在堆栈上找到一些解决方案。
这就是我尝试过的Dim labQuery = From Laboratory In objLab Where Laboratory.Name = "Telkom" Select Laboratory
答案 0 :(得分:0)
尝试这个
Dim objLab As New ArrayList
objLab.Add("Abc")
objLab.Add("Telkom")
objLab.Add("StackOverFlow")
Dim labQuery = From item In objLab
Where item.Equals("Telkom")
Select item
Console.WriteLine("Results :")
For Each s In labQuery
Console.WriteLine(s)
Next
Console.ReadLine()
…或
Dim objLab As New ArrayList From {
New Labaratory(3, "Abc"),
New Labaratory(2, "Telkom"),
New Labaratory(3, "StackOverFlow")
}
Dim labQuery = From item As Labaratory In objLab
Where item.Name.Equals("Telkom")
Select item
Console.WriteLine("Results :")
For Each s In labQuery
Console.WriteLine($"{s.Id} {s.Name}")
Next
Console.ReadLine()
您可以如下所示定义类实验室(Labaratory)
Public Class Labaratory
Public Sub New(i As Integer, n As String)
Id = i
Name = n
End Sub
Public Property Id As Integer
Public Property Name As String
End Class