Click here to Skip to main content
14,237,525 members

Conveniently Remove a List of Items From Another List

Rate this:
4.92 (6 votes)
Please Sign up or sign in to vote.
4.92 (6 votes)
14 Aug 2012CPOL
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

Comments and Discussions

 
-- There are no messages in this forum --
Tip/Trick
Posted 2 Jul 2012

Tagged as

Stats

20.4K views
7 bookmarked