A classic algorithm for calculating digits of pi
is the Gauss-Legendre algorithm. While it is not as fast as some of the more modern algorithms it does have the advantage of being understandable.
Let
a_0 = 1
b_0 = 1/Sqrt(2)
t_0 = 1/4
p_0 = 1
Then
a_(n+1) = (a_n + b_n) / 2
b_(n+1) = Sqrt(a_n * b_n)
t_(n+1) = t_n - p_n * (a_n - a_(n+1))^2
p_(n+1) = 2 * p_n
Then
pi =. (a_n + b_n)^2 / (4 * t_n)
Here (=.
means "approximately equal to") This algorithm exhibits quadratic convergence (the number of correct decimal places doubles with each iteration).
I'll leave it to you to translate this to C# including discovering an arbitrary-precision arithmetic library.