I'm looking for the fastest way to read data from a CSV file. I tried doing this two different ways.
Method #1: Reading all of the lines from the CSV file into an array an then iterating the array:
String[] csv = File.ReadAllLines(@"E:\be.csv");
for (int i = 0; i < csv.Length; i++)
{
tx.Text = csv[i];
tx.Refresh();
}
Method #2*: Using StreamReader
:
StreamReader sr = new StreamReader(new FileStream(@"E:\be.csv");
while (!sr.EndOfStream)
{
string seg = sr.ReadLine();
tx.Text = sr.ReadLine();
tx.Refresh();
}
Using StreamReader
seems to be a lot faster. Is there an even faster method to import data from a CSV file?