Skip to content

Instantly share code, notes, and snippets.

@rossmurray
Created February 16, 2014 18:12
Show Gist options
  • Save rossmurray/9038341 to your computer and use it in GitHub Desktop.
Save rossmurray/9038341 to your computer and use it in GitHub Desktop.
Generating a stream with while loop
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