Click here to Skip to main content
Click here to Skip to main content

Conveniently Remove a List of Items From Another List

By , 14 Aug 2012
 
Say you have two lists. You want to remove the items from the first list that already exist in a second list:
Dim listFirst As List(Of String) = New List(Of String)
Dim listSecond As List(Of String) = New List(Of String)

listFirst.Add("A")
listFirst.Add("B")
listFirst.Add("C")
listFirst.Add("D")
listFirst.Add("E")
listFirst.Add("F")

listSecond.Add("A")
listSecond.Add("D")
listSecond.Add("F")

Dim different As IEnumerable(Of String) = listFirst.Except(listSecond)
listFirst = different.ToList()
Result:
B
C
E 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Abdul Quader Mamun
Founder
Bangladesh Bangladesh
I have been developing software/web application since 2002 mainly on Microsoft technologies. I am a MCSD and MCTS. I have developed a wide range of Web, Desktop and Mobile applications.

I am vast experience with Telerik technologies.

I am also experience with other technologies.
Follow on   Google+

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5 PinmemberTom from Hamburg, Germany14-Aug-12 4:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130617.1 | Last Updated 14 Aug 2012
Article Copyright 2012 by Abdul Quader Mamun
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid