Calculate the First 1,000-Digit Fibonacci Number C# with Example
Include using System.Numerics and add a reference to System.Numerics to the project.
static void Main(string args)
BigInteger l1 = 1;
BigInteger l2 = 1;
BigInteger current = l1 + l2;
while (current.ToString().Length < 1000)
l2 = l1;
l1 = current;
current = l1 + l2;
This simple algorithm iterates through Fibonacci numbers until it reaches one at least 1000 decimal digits in length,
then prints it out. This value is signiﬁcantly larger than even a ulong could hold.
Theoretically, the only limit on the BigInteger class is the amount of RAM your application can consume.
Note: BigInteger is only available in .NET 4.0 and higher.