BigInteger overloads all the arithmetic operators, as well as the comparison, equality, modulus (%), and negation operators.
using System;
using System.Numerics;
class Sample
{
public static void Main()
{
BigInteger b = BigInteger.Pow(10, 20);
Console.WriteLine(b * b);
}
}
The output:
10000000000000000000000000000000000000000
Add two big numbers together.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
class MainClass
{
static void Main(string[] args)
{
// Create a new big integer.
BigInteger myBigInt = BigInteger.Multiply(Int64.MaxValue, 2);
// Add another value.
myBigInt = BigInteger.Add(myBigInt, Int64.MaxValue);
// Print out the value.
Console.WriteLine("Big Integer Value: {0}", myBigInt);
// Wait to continue.
Console.WriteLine("\n\nMain method complete. Press Enter");
Console.ReadLine();
}
}
The output:
Big Integer Value: 27670116110564327421
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. |