none
list RRS feed

  • Question

  • Hi,

    I've lists like the below:

     List < int > list1 = new List < int >();

     list1.Add(12);

    list1.Add(13);

    list1.Add(14);

    list1.Add(15);

    list1.Add(16);

    list1.Add(17);

     List < int > list2 = new List < int >();

     list2.Add(13);

    list2.Add(14);

    list2.Add(15);

    // Applied some filter on list2 and got list3.

     List < int > list3 = new List < int >(); 

     list3.Add(13);

    list3.Add(15);

     I need result :12, 13, 15, 16, 17. Only 14 should be eliminated from list1 since 14 is not in the list3. List3 is the list I got after applying some filter on list2.

     Thanks in advance.

     

     

     

     

     

     

     

     

    Friday, August 20, 2010 9:44 PM

Answers

  • create a new list to match the difference between list2 and list3, them remove the matched results from list1


    List<int> newlist = list2.Where(i => list3.Contains(i) == false).ToList<int>();
    list1.RemoveAll(i => newlist.Contains(i));
    Saturday, August 21, 2010 11:43 AM