Created
September 26, 2014 19:33
-
-
Save ronnieoverby/fdb1c760d2d8b13cb182 to your computer and use it in GitHub Desktop.
Helping someone using CoreTechs.Common Nuget package.
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 filePath = @"C:\Users\roverby\Desktop\New Text Document.txt"; | |
using (var reader = File.OpenText(filePath)) | |
{ | |
// if you can count on your text file being relatively small | |
// you can buffer the records into memory and use as many times | |
// as you like | |
var fileContents_Buffered = reader.ReadCsv().ToArray(); | |
// but if you're dealing with big files | |
// then you can seek back to the beginning of the stream | |
// each time you need to read | |
// note this only works when the BaseStream supports seeking | |
reader.BaseStream.Position = 0; | |
var fileContents = reader.ReadCsv(); | |
// reading doesn't actually occur until enumeration | |
foreach (var record in fileContents) | |
{ | |
// do something with record | |
} | |
// otherwise you should create a new StreamReader | |
// each time you want to read | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment