C# read csv file row & columns values?

sandrine10

Power Member
Joined
Apr 14, 2010
Messages
779
Reaction score
88
Hi mates,

Spent all the day searching how to read a csv file with no succes in practice, what i want do is getting rows and columns values using streamreader & increament statements:

Example of the file:
userid1;password1
userid2;password2
userid3;password3
userid4;password4

Anyone for help?!
 
Something like this perhaps?

Code:
var reader = new StreamReader(File.OpenRead("input.txt"));
var data = new List<List<string>>();
        
while (!reader.EndOfStream)
{
    var line = reader.ReadLine();
    var values = line.Split(';');
            
    data.Add(new List<String> { values[0], values[1] });
}

Console.WriteLine(data[0][0]); //  -> userid1
Console.WriteLine(data[0][1]); //  -> password1
 
Back
Top