I have a .csv file that currently is read all the lines:
string csv = File.ReadAllText(@inputfile);
suppose there are 100 lines inside that file. I want to read it only from the second line until the 50th lines. how to do that in C#?
I have a .csv file that currently is read all the lines:
string csv = File.ReadAllText(@inputfile);
suppose there are 100 lines inside that file. I want to read it only from the second line until the 50th lines. how to do that in C#?
You can use ReadLines
method with LINQ:
File.ReadLines(inputFile).Skip(2).Take(48);
Try this :
var lines = File.ReadLines("inputfile.csv").Skip(1).Take(49);
modified answer based on all comments
You can read all lines, skip the first one and take the remaining 49
List<String> lines = File.ReadAllLines(@inputFile).Skip(1).Take(49).ToList()