How to Get Factorial Value in C#

  1. public static int Factorial(this int i)  
  2.         {  
  3.             int factorial = 1;  
  4.             for (int j = i; j > 0; j--)  
  5.             {  
  6.                 factorial *= j;  
  7.             }  
  8.             return factorial;  
  9.         }  
 And call this method as following: 
  1. int i = 5;  
  2.            
  3. Console.WriteLine("Factorial of {0} is {1}", i, i.Factorial());