2015-02-20 09:02:09 -05:00
|
|
|
using System.IO;
|
2020-02-17 23:21:07 -08:00
|
|
|
using System.Linq;
|
2015-02-20 09:02:09 -05:00
|
|
|
|
2020-02-17 23:21:07 -08:00
|
|
|
namespace CSV_data_manipulation
|
2015-02-20 09:02:09 -05:00
|
|
|
{
|
2020-02-17 23:21:07 -08:00
|
|
|
class Program
|
2015-02-20 09:02:09 -05:00
|
|
|
{
|
2020-02-17 23:21:07 -08:00
|
|
|
static void Main()
|
2015-02-20 09:02:09 -05:00
|
|
|
{
|
2020-02-17 23:21:07 -08:00
|
|
|
var input = File.ReadAllLines("test_in.csv");
|
|
|
|
|
var output = input.Select((line, i) =>
|
2015-02-20 09:02:09 -05:00
|
|
|
{
|
2020-02-17 23:21:07 -08:00
|
|
|
if (i == 0)
|
|
|
|
|
return line + ",SUM";
|
|
|
|
|
var sum = line.Split(',').Select(int.Parse).Sum();
|
|
|
|
|
return line + "," + sum;
|
|
|
|
|
}).ToArray();
|
|
|
|
|
File.WriteAllLines("test_out.csv", output);
|
2015-02-20 09:02:09 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|