I have a method that will get two strings and return the sum of them in string format.
I use string since there will be +30 digits. I'm having trouble converting to add up. :
I have a method that will get two strings and return the sum of them in string format.
I use string since there will be +30 digits. I'm having trouble converting to add up. :
As you're talking about converting to ulong
I'll start from the beginning that strings represent integers.
public string Somar(string numA, string numB)
{
BigInteger bigA = BigInteger.Parse(numA);
BigInteger bigB = BigInteger.Parse(numB);
return BigInteger.Add(bigA, bigB).ToString();
}
If you want to treat float or double switch BigInteger with BigDecimal . An exception of type FormatException will be thrown if it can not parse .
If you are using .Net Framework 4.0 or higher you can use BigInteger . You will only need to reference the following System.Numerics
assembly.