以下のcsvデータを要素ごとに取り出す方法です。
必要なデータだけを抜粋したいときや、まとめて計算を行いたいときなどに便利かと思います。

一部データのパスやデータ処理の部分は必要に応じて変更が必要です。
private void Button_Click(object sender, RoutedEventArgs e)
{
string csvFile = @"C:\Users\eggam\Desktop\csvTest.csv"; //データのパス
List<string> date = new List<string>();
List<string> count = new List<string>();
List<string> cost = new List<string>();
using (StreamReader reader = new StreamReader(csvFile))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine(); //1行のデータ
string[] datas = line.Split(','); // , で区切られたデータ
date.Add(datas[0]);
count.Add(datas[1]);
cost.Add(datas[2]);
}
}
//テキストボックスに結果を出力
countTxt1.Text = count[1].ToString();
countTxt2.Text = count[2].ToString();
countTxt3.Text = count[3].ToString();
countTxt4.Text = count[4].ToString();
costTxt1.Text = cost[1].ToString();
costTxt2.Text = cost[2].ToString();
costTxt3.Text = cost[3].ToString();
costTxt4.Text = cost[4].ToString();
}
コメント