Average Speed - CSharp System

CSharp examples for System:Math Geometry

Description

Average Speed

Demo Code


using System;//  w w w  . j  a  v a2 s  .c o  m

public class Main{
        /// <summary>
        /// 
        /// </summary>
        /// <param name="distance">meters</param>
        /// <param name="timeElapsed">time elapsed</param>
        /// <returns>km/h</returns>
        public static double AverageSpeed(double distance, TimeSpan timeElapsed)
        {
            return timeElapsed.TotalHours > 0 ? (distance / 1000) / timeElapsed.TotalHours : 0;
        }
}

Related Tutorials