I have code like this were I am repeatedly doing something and I want to get the avergae time it takes to complete that task.
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);
But I get an error on the second to last line saying I can't convert method group 'Average' to 'System.TimeSPan'
try this:
TimeSpan timeaverage = TimeSpan.FromMilliseconds(TimeDisplay.Average(i=>i.TotalMilliseconds));
TimeSpan timeaverage = TimeSpan.FromTicks(Convert.ToInt64(TimeDisplay.Average(ts => ts.Ticks)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With