You should consider using System.Numerics.BigInteger
data type. It represents an arbitrarily large signed integer. They have virtually no limit at all unlike you might have observed for other number data types available in .NET framework. You can read more about it here.
To use this structure you need to refer System.Numerics.dll in your project and then include below namespace at the top of the code file:
using System.Numerics;
You can go through this post on how to add reference to an assembly in case you get stuck somewhere.
Below is the sample code showing how to parse a very large number string and convert it into BigInteger
:
var aVeryVeryHugeNumber = System.Numerics.BigInteger.Parse("31415926535897932384626433832795");
If you try to parse such a string representing a huge number, then it will result in System.OverflowException
even with ulong.Parse
data type. It fails with below error message:
Value was either too large or too small for a UInt64.