Converting a string into BigInteger

后端 未结 2 867
悲&欢浪女
悲&欢浪女 2021-01-17 17:29

I have the following code that creates a very big number (BigInteger) which is converted then into a string.

// It\'s a console app         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-17 17:33

    Here is another approach which is faster compared to BigInteger.Parse()

    public static BigInteger ToBigInteger(string value)
    {
        BigInteger result = 0;
        for (int i = 0; i < value.Length; i++)
        {
            result = result * 10 + (value[i] - '0');
        }
        return result;
    }
    

提交回复
热议问题