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 Articles
- 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
- Code performance on double for loop compare to linq/lambda
- FirstOrDefault: Default value other than null
- Is linq's let keyword better than its into keyword?
- How to count the number of code lines in a C# solution, without comments and empty lines, and other redundant stuff, etc?
- I am wondering about the state of connection and impact on code performance by 'yield' while iterating over data reader object
- Something better than .ToArray() to force enumeration of LINQ output
- LINQ query expressions that operate on types (monads?) other than IEnumerable<T> -- Possible uses?
- Is AsList() better than ToList() with IDbConnection.Query() which returns IEnumerable?
- Anyone found a use of "var" other than for LINQ?
- Linq select match list from other list performance
- Is there a better way to return the next item in a list and loop from the end to the front?
- .NET String parsing performance improvement - Possible Code Smell
- C# linq order by and other statements with foreach, is there a performance difference?
- Array get min value bigger than other value
- LINQ Source Code Available
- Is it bad practice to use LINQ to loop over and perform actions rather than just select data?
- In Memory Data Cache for Performance in .Net Applications
- How to do a GroupJoin based on other predicate than equality?
- .NET 4 Code Contracts: "requires unproven: source != null"
- Performance tuning C# permutations and SHA1 code
- How can a string with null give other result than null
- Querying DocumentDB using a property other than Id
- Avoid extra loop and could not find implementation of query pattern for source type int Select not found
- LINQ: using IEnumerable.Count() or IList.Count for better performance
- Ensure IQueryable<T>.Where() runs a SQL query rather than filtering in memory
- Can you use LINQ with in memory objects rather than SQL Server queries to improve performance?
- increase Performance of the code
- LINQ GroupBy using anonymous types working better than it should
- How to use async within a lambda which returns a collection
- LINQ and a natural sort order
- Chart of IEnumerable LINQ equivalents in Scala?
- LINQ versus yield
- EntityReference can have no more than one related object
- Windows Phone - LongListSelector grouped items by date and ordered by date
- Optimum performance in tag (keyword) feature implementation in ASP.NET MVC
- Is it possible to disable proxy in one Entity Framework query?
- LINQ to SQL and compiled queries
- How to allow null to be added to database
- Entity Framework - LINQ statement with WHERE clause based on NULLABLE parameter
- C# WinForm Excel check empty sheets function-works but too slow(15 sheets 30 seconds)
- MVC4 lambda expression for SimpleMembership
- Getting last item in tree hierarchy
- linq to sql navigation properties simple example
- Linq to XML - parse a node into dictionary
- Which is the better method to use LINQ?
- Linq expression with multiple joins with condition in each join
- Linq to XML selecting children list
- Is there a quick way to say If notempty x = y else x = default in a Linq where query