CSV數據爲.txt,總結總和從csv文件總計爲.txt
string fileName = "../../TechFiles/";
using (var reader = new StreamReader(ConfigurationManager.AppSettings["ConfigurationSource"]))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
string fullFileName = fileName + values[4] + ".txt";
List<helper> package = new List<helper>
{
new helper() { bankName = values[4], amount = double.Parse(values[6])}
};
List<ResultLine> result = package.GroupBy(i => i.bankName)
.SelectMany(cl => cl.Select(
csLine => new ResultLine
{
bankName = csLine.bankName,
Quantity = cl.Count().ToString(),
amount = cl.Sum(c => c.amount),
}))
.ToList<ResultLine>();
List<string> listA = new List<string>();
foreach (var book in result)
{
if (!listA.Contains(book.bankName))
{
listA.Add(book.bankName);
File.WriteAllText(fullFileName,
book.bankName + " " + book.amount + " " + book.Quantity);
}
}
我把在app.config CSV路徑則檢索所有的數據到文本文件中的所有金額,但問題是我想要一些我的value[4]
這是一個標題和所有額頭的總和,但它只返回一個單一的金額,所以我需要一種方法來傳遞所有的金額同時,所以我可以總和總額。
難道你不只是想通過每一行循環外的'GroupBy'位? – Jamiec 2015-02-06 14:32:31
List package = new List { new helper(){bankName = values [4],amount = double.Parse(values [6])} };這是我的問題所在,因爲它檢索一行代替所有行,所以它doensnt總結他們 –
Stshedaz
2015-02-06 15:03:45