Trying to add a column to the end of a cvs file, which will just count up the number of lines (or can all be the same number it doesn\'t really mater) as the main aim is to
Why so many materializations ReadAllLines()
, .ToList()
? Why not just
String filePath = @"C:/CSV/test.csv";
var csv = File.ReadLines(filePath) // not AllLines
.Select((line, index) => index == 0
? line + ",Column 4"
: line + "," + index.ToString())
.ToList(); // we should write into the same file, that´s why we materialize
File.WriteAllLines(filePath, csv);