我有兩個集合,比較它們並希望獲得不匹配的項目並放入新的集合。我不想使用2 foreach循環的傳統方法。如何使用linq和lambda表達式來實現它? 例如C#:使用Linq&Lambda獲取2個集合之間無與倫比的元素
int[] collection1 = new int[] { 1, 2, 3, 4, 5 };
int[] collection2 = new int[] { 2, 3 };
// Goal: Using Linq and Lambda Expression: the new collection3 should contain 1, 4, 5
編輯:抱歉我忘記提及:collection2是collection1的子集,因此collection2中的所有元素都必須存在於collection1中。
請說明:應該是什麼結果如果集合是「{1,2}」和「{2,3}」? – Henrik
嗨Henrik,謝謝。我編輯過。 – MagB