Click here to Skip to main content
12,244,802 members (55,831 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

13.5K views
7 bookmarked
Posted

Conveniently Remove a List of Items From Another List

, 14 Aug 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Convenient way to remove items from list when items exist in second list.
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)

Share

About the Author

Abdul Quader Mamun
Team Leader
Bangladesh Bangladesh
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
Tom from Hamburg, Germany14-Aug-12 5:09
memberTom from Hamburg, Germany14-Aug-12 5:09 

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

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

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