miércoles, 20 de marzo de 2013

Forma de calcular pi desde linq


var startNew = Stopwatch.StartNew();
var mightBePi = Enumerable.Range(0, 100000000).Aggregate(0d, (tot, next) => tot + Math.Pow(-1d, next)/(2*next + 1)*4);
Console.WriteLine(startNew.ElapsedMilliseconds);

Fuente: http://www.genbetadev.com/metodologias-de-programacion/el-verdadero-coste-de-los-bloques-trycatch