I am simply practicing in C#. I am mostly used to Java but I have been unable to figure out how to read a .CSV file , store it and the print out it's contents into the console. This is what I have so far. What am I doing wrong?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Microsoft.VisualBasic.FileIO;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
String path = "C:\\Desktop\\csvTestFilePractice\\";
String file1 = "testFile1.csv";
ArrayList arryList1 = new ArrayList();
String[] dataArray1;
TextFieldParser CSVFile1 = new TextFieldParser(path + file1);
CSVFile1.SetDelimiters(",");
dataArray1 = CSVFile1.ReadFields();
int count = 0;
while (!CSVFile1.EndOfData)
{
dataArray1 = CSVFile1.ReadFields();
Console.WriteLine(dataArray1);
}
Console.Read();
}
}
}
Also this is the file I am testing with.
______Excel View
ID Name Phone State
1 Colt 864-367-8399 SC
2 Terry 864-367-8400 GA
3 Joe 864-367-8401 FL
4 Mark 864-367-8402 NC
5 Ashley 864-367-8403 CO
____Notepad View
ID,Name,Phone,State
1,Colt,864-367-8399,SC
2,Terry,864-367-8400,GA
3,Joe,864-367-8401,FL
4,Mark,864-367-8402,NC
5,Ashley,864-367-8403,CO
Thank you for any advice