With a couple of error checks in place, it works for me on a test CSV file:
{
StreamReader reader = new StreamReader(File.OpenRead(@"D:\Temp\ContactsShort.csv"));
List<string> listA = new List<String>();
List<string> listB = new List<String>();
List<string> listC = new List<String>();
List<string> listD = new List<String>();
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
if (!String.IsNullOrWhiteSpace(line))
{
string[] values = line.Split(',');
if (values.Length >= 4)
{
listA.Add(values[0]);
listB.Add(values[1]);
listC.Add(values[2]);
listD.Add(values[3]);
}
}
}
string[] firstlistA = listA.ToArray();
string[] firstlistB = listB.ToArray();
string[] firstlistC = listC.ToArray();
string[] firstlistD = listD.ToArray();
}
So, I would start looking at your CSV file, and at the output you actually get.
BTW: Don't use
var
as a declaration all the time - it just shows you are too lazy to think about your datatypes. Particularly as Intellisense will fill out the right hand side for you in most case if you do the left...