I'm trying to read an Excel CSV file into a list. I'm able to read in the file and split the fields with no problem. When I loop through the split data and write it to the console it properly displays like this:
003 2 123456789 10 240 ME24-198 100 3/1/2021 3/31/2021 003 2 123456799 11 240 ME24-199 60 3/1/2021 3/31/2021 003 2 123676789 12 240 ME24-153 240 3/1/2021 3/31/2021 003 2 483456789 13 240 ME24-100 500 3/1/2021 3/31/2021 003 2 602456789 14 240 ME24-207 375 3/1/2021 3/31/2021
But when I try to put the data into list zdList my data prints like this:
003 2 123456789 10 240 ME24-198 100 3/1/2021 3/31/2021
Here's what my code looks like:
public partial class Form1 : Form
{
private List<ZDispatchm> zdList;
private bool errExit;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Refresh_Zdispatchm()
{
var reader = new StreamReader(File.OpenRead(IqmsDispatchFile));
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
string[] zdList = line.Split(',');
foreach (string item in zdList)
{
Console.WriteLine(item);
}
}
}
}
I've search this forum and tried numerous suggestions, including these:
How to split a string into substrings and store into a List - c#
read CSV file into a List of strings and then loop to identify an item
How to read csv file and store each cell value into a list (C#) <-- THIS IS THE ONE I'M TRYING TO USE
I've tried this:
Console.WriteLine(item[0], item[1], item[2] . . .etc);
and
Console.WriteLine(item[0].ToString, item[1].ToString);
But they don't work. The compiler emits this error:
CS1503: Cannot convert from 'method group' to 'string'.
In the end, I want the data in the list. I was only printing to the console to confirm that I had access. I'm not sure what I'm doing wrong so I'm wondering if anyone can steer me in the right direction.