C#: Gets unmatched elements between 2 collections with Linq & Lambda -


i have 2 collections, compare them , want unmatched items , put new collection. don't want use conventional method using 2 foreach loop. how implement using linq , lambda expression? e.g.

    int[] collection1 = new int[] { 1, 2, 3, 4, 5 };     int[] collection2 = new int[] { 2, 3 };     // goal: using linq , lambda expression: new collection3 should contain 1, 4, 5 

edited: sorry forget mention: collection2 subset of collection1, therefore elements in collection2 must exist in collection1.

var result = collection1.except(collection2).concat(collection2.except(collection1)).toarray(); 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -