Mega Code Archive

 
Categories / C# / Development Class
 

Factorial value

using System.Collections.Generic; using System.Linq; using System; public static class Utilities {     public static ulong Factorial(uint value)     {         // ulong.MaxValue is smaller than the result of 21!         if (value > 20)         {             throw new ArgumentException("value");         }         if (value == 0)         {             return 1;         }         else         {             return value * Factorial(value - 1);         }     } }