Created
February 16, 2014 18:12
-
-
Save rossmurray/9038341 to your computer and use it in GitHub Desktop.
Generating a stream with while loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var records = GetRecordStream(); | |
foreach(var record in records) | |
{ | |
SaveRecord(record); | |
} | |
} | |
private IEnumerable<Record> GetRecordStream() | |
{ | |
bool moreRecords = true; | |
while(moreRecords) | |
{ | |
var record = ReadNextRecord(); | |
if(record != null) | |
{ | |
yield return record; | |
} | |
else | |
{ | |
moreRecords = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment