Your code doesn't actually make sense. I just tested the addition of those two BigInteger
values like this:
Dim one As BigInteger = BigInteger.Parse("99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999")
Dim two As BigInteger = BigInteger.Parse("9999999999999999999999999999999999999999999999999999999999999999999999999")
Console.WriteLine((one + two).ToString)
Console.ReadLine()
and like this:
Dim str1 = "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
Dim str2 = "9999999999999999999999999999999999999999999999999999999999999999999999999"
Dim one As BigInteger
Dim two As BigInteger
BigInteger.TryParse(str1, one)
BigInteger.TryParse(str2, two)
Console.WriteLine((one + two).ToString)
Console.ReadLine()
and it worked exactly as expected both times.
You really need to turn Option Strict On
because your code is assigning String
values to BigInteger
variables, which is almost certainly what's causing your issue. If you have a String
that you want to convert to a BigInteger
then you should either use BigInteger.Parse
when the value is known to be valid or BigInteger.TryParse
when it's not.
Your code doesn't really make sense because you first assume that implicit conversions will be OK but then you go ahead and use TryParse
anyway. It gets even more nonsensical because you use TryParse
to populate what appears to be the wrong BigInteger
variable. You need to understand what your code is supposed to do before you write, otherwise you can end up with nonsense and have no idea that it doesn't do what you didn't know you wanted to do in the first place.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…