Reputation: 634
I have two different types of objects that have ID fields with potentially matching IDs. The FindAll operation returns the correct non-matching objects whereas the Where operation returns all objects. Can someone help me understand why?
var _kenticoIDs = new HashSet<string>(_kenticoSessions.Select(p => p.AttendeeInteractiveSessionID));
var list = _aiSessionIDList.FindAll(p => !_kenticoIDs.Contains(p.SessionID));
var ienum = _aiSessionIDList.Where(p => !_kenticoIDs.Contains(p.SessionID));
EDIT: If I perform a .ToList() on the resultA variable then resulting list is the same as the result variable. However when I inspect the two variables (result/resultA) before the .ToList() one has 6 values and one has 63 values. I feel like I'm missing something obvious.
Upvotes: 1
Views: 1209
Reputation: 10515
I think the issue you are having is understanding Linq. Where is a Linq extension method whereas FindAll is a List method. Linq expressions are not evaluated until they are enumerated over, or turned into a list/array.
Upvotes: 2