Skip to content

Instantly share code, notes, and snippets.

@davkean
Created August 20, 2014 16:59
Show Gist options
  • Save davkean/986d8ac6cd65f585e442 to your computer and use it in GitHub Desktop.
Save davkean/986d8ac6cd65f585e442 to your computer and use it in GitHub Desktop.
Leaking enumerable
DirectoryInfo info = new DirectoryInfo(@"C:\Temp");
IEnumerable<FileInfo> files = info.EnumerateFiles("*.txt")
.Where(f => f.CreationTimeUtc > lastWeek);
foreach (FileInfo file in files)
{
} // With your proposal, where does Dispose get called on the strong-typed enumerable returend by EnumerateFiles?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment