我在.csv文件中有一些如下所示的数据:
1, task1, 00:00:02.0000000
1, task2, 00:00:00.3529381
1, task3, 00:00:01.1604731
1, task4, 00:00:00.1413738
第三列是TimeSpans。我需要计算它们的平均值,最小值,最大值等。我在尝试在线方法时遇到的问题是它回复为0.我已经尝试过:
public Log(string a_action, string a_time, string a_executionTime, string a_studentLogin)
{
Action = a_action;
Time = a_time;
ExecutionTime_s = a_executionTime;
ExecutionTime_ts = TimeSpan.ParseExact("0:0", @"h\:m",
CultureInfo.InvariantCulture);
ExecutionTime_l = Convert.ToInt64(ExecutionTime_ts.TotalMilliseconds);
ExecutionTime_d = (double)ExecutionTime_ts.TotalMilliseconds;
}
public void Calc()
{
List<Log> logList = CSVToList.GetList();
double doubleAverageTicks = logList.Average(timeSpan => timeSpan.ExecutionTime_d);
long longAverageTicks = Convert.ToInt64(doubleAverageTicks);
TimeSpan sp = new TimeSpan(longAverageTicks);
}
建议赞赏..还有我的linq sux
答案 0 :(得分:1)
TimeSpan sp = TimeSpan.FromMilliseconds(doubleAverageTicks);