如果我有 2 个类并且想从每个类中获取 2 个属性,并将它们组合成一个单独的集合,那么如何使用 linq 来完成?
说这两个类是:
class guitars
public ID
public title
public manufacturer
end class
class drums
public ID
public title
public manufacturer
end class
我试过这个,但没有奏效:
Private Interface Instruments
Property ID As String
Property name As String
End Interface
Dim results = From item In guitars _
Select New Instruments() With _
{ _
.ID = item.ID, _
.name = item.Title _
}
Dim results2 = From item In drums _
Select New Instruments() With _
{ _
.ID = item.ID, _
.name = item.Title _
}
Dim combined = results + results2