Most efficient way to compare two lists and delete the same

前端 未结 5 1398
执笔经年
执笔经年 2021-01-19 16:57

I want to compare two lists and get the valid words into a new list.

var words = new List();
var badWords = new List();

//this i         


        
5条回答
  •  面向向阳花
    2021-01-19 17:21

    https://msdn.microsoft.com/library/bb908822(v=vs.90).aspx

    var words = new List();
    var badWords = new List();
    
    //this is just an example list. actual list does 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");
    
    var result = words.Except(badWords).ToList();
    

    Edit: Got in late.

提交回复
热议问题