score:3
Accepted answer
your foreach
version calls var localenumertaor = contactservice.download();
inside the profile action, while the enumerator version calls it outside of the profile
call.
on top of that, the first execution of the iterator version will exhaust the items in the enumerator, and on subsequent iterations itemscollection.movenext()
will return false and skip the inner loop entirely.
Source: stackoverflow.com
Related Query
- Why one loop is performing better than other memory wise as well as performance wise?
- C# LINQ Find List Inside Another List, Better way to code this than a foreach loop
- Why does Enumerable.Single() iterate all elements, even when more than one item has already been found?
- Why does Single() not return directly when more than one element is found?
- Better code for avoiding one dictionary - Case Sensitivity Issue
- Why first linq act 20 times faster than second one [Getting Max value]
- Why can I not do more than one level of include in my LINQ statement?
- Why does this work but the other one fails( Linq To Xml)
- Convert this LINQ code back to a Loop (or Why is this object sometimes null)
- Why LINQ returns other column value than expected?
- Why changing one item in a linq group affects other items in the same group?
- Why is For Each loop slower than linq's outer join in this example?
- Why does VB.NET Linq Lambda work one way but not the other
- Why Entity Framework Code First one to many Doesn't work properly
- Code performance on double for loop compare to linq/lambda
- Convert string[] to int[] in one line of code using LINQ
- FirstOrDefault: Default value other than null
- Sequence contains more than one element
- Linq code to select one item
- Why is LINQ JOIN so much faster than linking with WHERE?
- LINQ OrderBy with more than one field
- Is linq's let keyword better than its into keyword?
- Why is LINQ .Where(predicate).First() faster than .First(predicate)?
- Why use .AsEnumerable() rather than casting to IEnumerable<T>?
- How can I efficiently determine if an IEnumerable has more than one element?
- Why is OfType<> faster than Cast<>?
- Why is "Divide by Zero" or any other exception not raised?
- Why does ReSharper suggest I convert a for loop into a LINQ expression?
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- Why does XmlReader skip every other element if there is no whitespace separator?
More Query from same tag
- How to apply Expression<Func<string,bool>> to a string property in Linq2Sql .Where() clause?
- linq to generic list C#
- Linq query order by for string
- How to select replicated items in a list with linq?
- Advice With Repository/Service Layer Design Pattern
- Determine the position of an element in an IQueryable
- Collection-valued parameters with The Entity Framework?
- Can't access to middle table in LINQ with entity framework?
- Change this Loop by LINQ?
- Using LINQ query result for data source for GridControl c#
- Get Distinct List from csv file based on first column
- Remove duplicates by field from one table using another using LINQ
- Multiple column join in linq
- Linq query to get count with multiple column values coming from condition on another column
- Writing a function (method) to print out the transaction details
- Linq sub list Problem
- How to implement Gradient Descent algorithm in C# using LINQ?
- LINQ conditional select from table and return multiple column as a single list
- C# Linq to XML getting the elements where value of name contains a specific string
- Combine 2 LINQ queries into 2
- C# Linq to sum and group XML
- Pivot list data using LINQ
- Linq-To-Sql convert string to date with specific format
- Can I populate a list of my own class directly in LINQ?
- Sorting multiple lists on the basis of common field
- Linq statement with nullable values could not be translated
- Code throws Invalid cast exception: linq-sql join two tables
- How can I use the .Select(T, index) overload in a LINQ query?
- Issue converting varchar to datetime in bulk insert statement
- Dynamically Create WHERE Clause in Razor Page Linq