Q:

CSV file contents to two dimensional array

This question has been asked several times with different inputs so I thought of reposting it with my requirement.
I have a CSV file which contents string fields in the way given below.
idnum,name1, name2,groupid

idnum,name1, name2,groupid

idnum,name1, name2,groupid

example 
s001,sahil,payap,gid0

s002,Amir,Khan,gid02

d003,hrithik,roshan,gid03

I have two dimensional string array. I want to read row by row to my two dimensional array.
When it read it should be like this
arr[0][0]=s001

arr[0][1]=name1

arr[0][2]=name2

arr[0][3]=gid01

arr[1][0]=s002

arr[1][1]=Amir

arr[1][2]=Khan

arr[1][3]=gid04

there are 40 records in a file and it should read till the end of the file.
I need to implement this in C#
Any code sample or any explanation would be great help.
I have no knowledge in csv file handling so please don't ask what did you try, at least if you could give me a code sample for reading just one string for a variable it would be a great help.
And please don't ask to go for another solution. 
Thanks.

A:

The simplest way to read a csv file in the way you suggest is probably:
var rows = File.ReadAllLines("myfile.csv").Select(l => l.Split(',').ToArray()).ToArray();

Then:
Console.WriteLine(rows[0][0]); // Will output s001
Console.WriteLine(rows[0][1]); // Will output sahil
Console.WriteLine(rows[0][2]); // Will output payap
Console.WriteLine(rows[0][3]); // Will output gid0
Console.WriteLine(rows[1][0]); // Will output s002
Console.WriteLine(rows[2][0]); // Will output d003

A:

The file would have to be read in line-wise. Each line would have to be separated using String.Split. Then the resulting strings would have to be trimmed using Trim, and finally would have to be written into the respective columns of the current row. However I totally second the comments above; more convenient would be to use some class or struct called Person and then to parse into a List<Person>.
The reading could be done as follows:
String line = String.Empty;
System.IO.StreamReader file =  new System.IO.StreamReader("c:\\file.txt");
while((line = file.ReadLine()) != null)
{
    String[] parts_of_line = line.Split(',')
    for ( int i = 0; i < parts_of_line.Length; i++ )
        parts_of_line[i] = parts_of_line[i].Trim();

    // do with the parts of the line whatever you like

}

