I have an IEnumerable variable named "query" which represents an entity framework query. If I do the following, will it enumerate the query more than once? My confusion is in "result" being an IEnumerable and not a List.
IEnumerable<T> result = query.ToList(); bool test = result.Any(); as apposed to this:
// Using List to only enumerate the query once List<T> result = query.ToList(); bool test = result.Any(); Also, I know this is silly, but would it enumerate twice if I do the following, or would it somehow know that "query" was already enumerated even though the result of the enumeration is not being used?
List<T> result = query.ToList(); bool test = query.Any(); Thanks!
ToList()would most likely convert yourIEnumerableto aList, so would iterate through it. ButAny()only checks if theIEnumerablecontains any elements, so it would almost sure not enumerate your result.queryis anIQueryable<T>