How to merge 2 IList collections?

  • Thread starter Thread starter David Shultz
  • Start date Start date
D

David Shultz

Can anyone show me how to cleanly merge 2 IList collections? Keeping
only unique items from the 2 lists?

--David
 
Hi David,
Can anyone show me how to cleanly merge 2 IList collections? Keeping
only unique items from the 2 lists?

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
 
Take advantage of Linq and use


foreach (var item in List2.Except(List1))
{
List11.Add(item);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top