c# - Most efficient way to compare two lists and delete the same -


i want compare 2 lists , valid words new list.

var words = new list<string>(); var badwords = new list<string>();  //this example list. actual list contain 700 records words.add("apple"); words.add("moron"); words.add("seafood"); words.add("cars"); words.add("chicken"); words.add("twat"); words.add("watch"); words.add("android"); words.add("c-sharp"); words.add("fool");  badwords.add("idiot"); badwords.add("retarded"); badwords.add("twat"); badwords.add("fool"); badwords.add("moron"); 

i looking efficient way compare lists , put 'good' words new list. finallist shouldn't contain "moron", "twat" , "fool".

var finallist = new list<string>(); 

or unnecessary create new list? happy hear ideas!

thank in advance

use enumerableexcept function storing in system.linq namespace

finallist = words.except(badwords).tolist(); 

most efficient way save time , fastest way it, because except implementation uses set, fast


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -