jae-l
9/8/2017 - 12:30 PM

BigInteger

Description of how to use BigInteger.

For example, to calculate factorial 100! we can use data type BigInteger (which is new as of .NET Framework 4.0 and is missing in the older .NET versions). This type represents an integer, which can be very large (for example 100,000 digits). There is no limit on the size of the numbers recorded in the class BigInteger (as long as you have enough RAM).

In order to use BigInteger, add a reference from our project to the assembly System.Numerics.dll (this is a standard .NET library for working with very large integers, which is not referenced by default by our VS projects). Adding a reference to it is done by right-clicking on the current project references in the Solution Explorer window of Visual Studio.

Search and choose the assembly System.Numerics.dll from the list.

Then we need to add "using System. Numerics; " before the beginning of the class of our program and replace decimal with BigInteger.

By BigInteger you can calculate 1000!, 10000! and even 100000! It will take some time, but OverflowException will not occur. The BigInteger class is very powerful but it works many times slower than int and long. For our unpleasant surprise there is no class "big decimal" in .NET Framework, only "big integer".