我無法圍繞如何創建此查詢。如果項目Cats列表包含的Cat對象與List2中其中一個Cat的ID相匹配,我需要選擇列表1中的項目。這可能嗎?謝謝LINQ select list子列表包含來自另一個列表的項目
List1<pet> List1 = new List<pet>(100);
List2<cat> List2 = new List<cat>(30);
//populate lists, some of the items in List2 (cat) will be in the List1 items Cats list
//classes
class pet{
string ID;
List<cat> Cats;
}
class cat {
string ID;
string name;
}
我有我的equals方法重寫檢查匹配的ID,這是更有效? – user2704766
在沒有匹配的情況下,相交一個會更快(無論如何,任何情況都必須通過整個集合)。當有很多可能的匹配時,任何事情都會變得更快(因爲它只發生一次匹配後就會停止)。我只給你了相交變體,因爲在我看來它看起來更漂亮。 –
謝謝你,你和Alexanders都工作得很好! – user2704766