Skip to content

Instantly share code, notes, and snippets.

@ronnieoverby
Created September 26, 2014 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronnieoverby/fdb1c760d2d8b13cb182 to your computer and use it in GitHub Desktop.
Save ronnieoverby/fdb1c760d2d8b13cb182 to your computer and use it in GitHub Desktop.
Helping someone using CoreTechs.Common Nuget package.
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