我正在尝试获得在任务上花费的平均时间。 关于如何添加时间表(分钟)列表的任何想法。这是我的代码的一个例子
For Each row As DataRow In rows
Dim current As TimeSpan = CType(row("started"),
DateTime).Subtract(row("Ended"))
OrderList1.Add(current)
Next
Dim Averagetime As TimeSpan = OrderList1.Add(OrderList1)/Orderlist1.count
答案 0 :(得分:0)
Dim Averagetime As TimeSpan = TimeSpan.FromMinutes(OrderList1.Sum(Function(x) x.TotalMinutes) / Orderlist1.count)
结束顺便说一句。我认为你必须在CType
使用row("Ended")
:
Dim current As TimeSpan = CType(row("started"),
DateTime).Subtract(CType(row("Ended"), DateTime))
答案 1 :(得分:0)
您可以使用:
Dim query = from row in theTable.AsEnumerable()
select (CType(row("started"), DateTime).Subtract(row("Ended"))).Ticks
Dim averageTime As TimeSpan = new TimeSpan(query.Average())