如何从对象数组和字符串数组的交集中获取对象集合?
例如,我有一个对象集合(Person 类)和一个字符串数组:
Public Class Person
Public lastName As String
Public firstName As String
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim personArray As List(Of Person)
Dim p1 As Person = New Person("Bill", "Fitch") : personArray.Add(p1)
Dim p2 As Person = New Person("Randy", "Roberts") : personArray.Add(p2)
Dim p3 As Person = New Person("Miles", "Johnson") : personArray.Add(p3)
Dim p4 As Person = New Person("Sandy", "Smith") : personArray.Add(p4)
Dim arrayNames() As String = {"Jones", "Roberts", "Smith", "Teague"}
'The Linq code
Dim query = From myPerson In personArray
Where myPerson.lastName = arrayNames
Select myPerson
End Sub
End Class
当然,Linq 代码不起作用,但 Linq 能做什么?