Reputation: 41
I have two list and wanna know which items are in the fist one and arn't in second one,
List<int> viewphonenumid = new List<int>();
List<int?> DtoPhonenumId = new List<int?>();
For instance viewphonenumid has {1,2,3,4,5,6} and DtoPhonenumId has{3,4,5,6} and I wanna have {1,2} in a new list.
Upvotes: 0
Views: 1705
Reputation: 539
try following:
List<int> result = new List<int>();
foreach(int element in viewphonenumid)
if(!DtoPhonenumId.Contains(element))
result.Add(element);
I hope that help
Upvotes: 0
Reputation: 31
var newList= viewphonenumid.Except(DtoPhonenumId).ToList();
You also can specify comparer.
http://msdn.microsoft.com/library/bb336390(v=vs.110).aspx
Upvotes: 1
Reputation: 1265
I suggest you to use Enumerable.Except http://msdn.microsoft.com/ru-ru/library/bb300779(v=vs.110).aspx
Something like this
(new List<int> {1,2,3,4}).Except(new List<int> {3,4})
Upvotes: 0
Reputation: 31239
Maybe something like this:
var newList= viewphonenumid.Where(v =>! DtoPhonenumId.Contains(v)).ToList();
Upvotes: 0