D David Shultz May 21, 2004 #1 Can anyone show me how to cleanly merge 2 IList collections? Keeping only unique items from the 2 lists? --David
Can anyone show me how to cleanly merge 2 IList collections? Keeping only unique items from the 2 lists? --David
F Frank Eller [MVP] May 21, 2004 #2 Hi David, Can anyone show me how to cleanly merge 2 IList collections? Keeping only unique items from the 2 lists? Click to expand... Let's assume List1 is the first list, List2 the second: ======= foreach ( object o in List2 ) if ( !List1.Contains( o ) ) List1.Add( o ); ======= Regards, Frank Eller
Hi David, Can anyone show me how to cleanly merge 2 IList collections? Keeping only unique items from the 2 lists? Click to expand... Let's assume List1 is the first list, List2 the second: ======= foreach ( object o in List2 ) if ( !List1.Contains( o ) ) List1.Add( o ); ======= Regards, Frank Eller
G gslam Joined Jan 5, 2011 Messages 1 Reaction score 0 Jan 5, 2011 #3 Take advantage of Linq and use foreach (var item in List2.Except(List1)) { List11.Add(item); }