LINQ except is not working when used for two list<string>

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
i tried to except two list. here is code

List<string> _lst1 = new List<string>();
_lst1.Add("cat");
_lst1.Add("dog");
_lst1.Add("hen");

List<string> _lst2 = new List<string>();
_lst1.Add("cat");
_lst1.Add("dog");
_lst1.Add("cow");

_lst1 = _lst1.Except(_lst2).ToList();

i though common item should be removed from list1. so list1 and list2 has two common item called cat and dog. so when i will except list1 from list2 then i though a new list will have only hen but i saw new list giving 4 items cat,dog,hen & cow.

where i made the mistake ?

Continue reading...
 
Back
Top