Click here to Skip to main content
11,708,312 members (72,839 online)
Click here to Skip to main content

Tagged as

Conveniently Remove a List of Items From Another List

, 14 Aug 2012 CPOL 11.5K 7
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
I have been developing software/web applications since 2002 mainly on Microsoft technologies.

I'm also experienced with other technologies.

I'm fan of well organized and effective coding.

A wide range of technologies, tools, languages, frameworks, components and design patterns I’m experienced with.

I’m a MCP, MCAD.NET, MCSD.NET.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
Tom from Hamburg, Germany14-Aug-12 4:09
memberTom 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.

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