If I have 2 classes and want to take 2 properties from each class, and combine them into a separate collection, how would this be done using linq?
Say the 2 classes are:
class guitars
public ID
public title
public manufacturer
end class
class drums
public ID
public title
public manufacturer
end class
I tried this, but it didn’t work:
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
You can make it much simpler than that.
Just make both classes implement the
IInstrumentinterface.You can then write