IMongoCollection<JobInfoRecord> records = ...
foreach (var record in records.Find(query).ToListAsync().Result)
{...}
Is it true that foreach iteration I compute .Result
value again and again?
IMongoCollection<JobInfoRecord> records = ...
foreach (var record in records.Find(query).ToListAsync().Result)
{...}
Is it true that foreach iteration I compute .Result
value again and again?
No, it's going to evaluate records.Find(query).ToListAsync().Result
once and then call GetEnumerator
on the result. Then each loop is going to call MoveNext
on the returned "Enumerator" and set record
to the Current
property of that "Enumerator" with the loop breaking when MoveNext
returns false
.