BigInteger

BigInteger lives in the new System.Numerics namespace in System.Numerics.dll.

BigInteger allows you to represent an arbitrarily large integer without any loss of precision.

You can implicitly cast from any other integral type to a BigInteger.

For instance:


using System;
using System.Numerics;

class Sample
{
    public static void Main()
    {
        BigInteger twentyFive = 25;  // implicit cast from integer

        Console.WriteLine(twentyFive);

    }
}

The output:


25

To represent a bigger number, use one of BigInteger's static methods, such as Pow (raise to the power):


using System;
using System.Numerics;

class Sample
{
    public static void Main()
    {
        BigInteger b = BigInteger.Pow(10, 20);
        Console.WriteLine(b);

    }
}

The output:


100000000000000000000

You can also Parse a string to get a BigNumber:


using System;
using System.Numerics;

class Sample
{
    public static void Main()
    {
        BigInteger googol = BigInteger.Parse("1".PadRight(100, '0'));
        Console.WriteLine(googol);
    }
}

The output:


1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.