This is an old question, nevertheless the answers did not satisfy me regarding to performance and optimization.
Here my optimized C# variant (distance in km, without variables and redundant calculations, very close to mathematical expression of Haversine Formular https://en.wikipedia.org/wiki/Haversine_formula).
Inspired by: https://rosettacode.org/wiki/Haversine_formula#C.23
public static class Haversine
{
public static double Calculate(double lat1, double lon1, double lat2, double lon2)
{
double rad(double angle) => angle * 0.017453292519943295769236907684886127d; // = angle * Math.Pi / 180.0d
double havf(double diff) => Math.Pow(Math.Sin(rad(diff) / 2d), 2); // = sinĀ²(diff / 2)
return 12745.6 * Math.Asin(Math.Sqrt(havf(lat2 - lat1) + Math.Cos(rad(lat1)) * Math.Cos(rad(lat2)) * havf(lon2 - lon1))); // earth radius 6.372,8?km x 2 = 12745.6
}
}