c# - 时间跨度平均值

标签 c# timespan

我有这样的代码,我重复做某事,我想获得完成该任务所需的平均时间。

        List<TimeSpan> TimeDisplay = new List<TimeSpan>();

        while(some condition)
        {
            Stopwatch sw = new Stopwatch();
                  sw.Start();
            TimeSpan temp;


            //DO SOMETHING\\

            sw.Stop();
            temp = sw.Elapsed
            TimeDisplay.Add(temp);

        }

        TimeSpan timeaverage = TimeDisplay.Average;

        System.Console.Writeline("{0}", timeaverage);

但我在倒数第二行收到一条错误消息,提示我无法将方法组“Average”转换为“System.TimeSPAn”

最佳答案

试试这个:

TimeSpan timeaverage = TimeSpan.FromMilliseconds(TimeDisplay.Average(i=>i.TotalMilliseconds));

关于c# - 时间跨度平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17682169/

相关文章:

c# - Silverlight 媒体播放器位置问题

c# - 获取 TimeSpan 中的总小时数

c# - 串行端口返回无效数据

c# - 其他对象上的 Unity3D IPointerDownHandler

c# - 修改 Visual Studio 2013 的模拟器/设备列表

C#:如何将特殊字符写入 ADLDS?

powershell - 从 ISO 8601 持续时间获取 DateTime 对象

c# - 如何在时间跨度内进行除法

c# - 如何将字符串 "1900-01-01 08:00:00.000"格式化为 HH :MM and add 30 minutes to it?

c# - 应用程序无法写入注册表,即使用户具有管理权限