Reputation: 1404
I want to pick elements out of a list based on if the elements in another list.
list1 = List<FileModel>(){..};
List2 = List<WindowModel>(){...};
List3 = List1.Where(d => List2.Select(x => x.FileName).Contains(d.FileName));
But I've got an error (Cannot implicitly convert System.Collections.Generic.IEnumberable<> to System.Collections.Generic.List<>). How to get it done here?
Upvotes: 0
Views: 87
Reputation: 1
Use ToList<FileModel>();
List1.Where(x => List2.Select(y => y.FileName).Contains(x.FileName)).ToList<FileModel>();
Upvotes: -2
Reputation: 1182
Use ToList() Method.
List1.Where(d => List2.Select(x => x.FileName).Contains(d.FileName)).ToList();
Upvotes: 4