Convert string number to BigInteger in CSharp
Description
The following code shows how to convert string number to BigInteger.
Example
// w ww . j a va2 s. c om
using System;
using System.Numerics;
public class Class1
{
public static void Main()
{
string stringToParse = String.Empty;
try
{
string string1, string2;
string1 = "99999999999999999999";
string2 = "88888888888888888888";
stringToParse = string1;
BigInteger number1 = BigInteger.Parse(stringToParse);
Console.WriteLine("Converted '{0}' to {1:N0}.", stringToParse, number1);
stringToParse = string2;
BigInteger number2 = BigInteger.Parse(stringToParse);
Console.WriteLine("Converted '{0}' to {1:N0}.", stringToParse, number2);
}
catch (FormatException)
{
Console.WriteLine("Unable to parse {0}.", stringToParse);
}
}
}
The code above generates the following result.