HomeCSharpWhat is BigInteger in C# 4.0?

What is BigInteger in C# 4.0?

This blog post will explain what is a BigInteger and why we need it in C#.

When talking to one of my friend today , he mentioned about the BigInteger data type in Java . I was wondering what this datatype equivalent be in C# and ended up to see this datatype in C# too .

This is available in C# 4.0 .

What is BigInteger in C# 4.0?

The BigInteger represents a large signed integer where its value has no upper or lower bounds so that it can be used on operation on very large values

To use the BigInteger in C# , one might need to add the reference of the System.Numerics assembly to the project .

What is BigInteger in C# 4.0 ?

In the following example , i created a BigInteger with a value that is equivalent to the Power of Int64.MaxValue . ( Int64.MaxValue X  Int64.MaxValue X  Int64.MaxValue ) .

BigInteger MyValue1 = BigInteger.Multiply(Int64.MaxValue, Int64.MaxValue);
MyValue1 = BigInteger.Multiply(MyValue1, Int64.MaxValue);
MessageBox.Show("Value= " + MyValue1.ToString() + "\n" + " Length=" + MyValue1.ToString().Length.ToString());

Just see the resulting output and the length of the variable .. Its is quite BIG.

What is BigInteger in C# 4.0 ?

Note that using BigInteger may cause Out of Memory Exception when its value grow too large

Want to explore more on BigInteger in .NET Framework 4.0 ? Check BigInteger Structure in MSDN . It has a great content about the BigInteger

    1 Comment

  1. โหลดหนัง
    May 26, 2011
    Reply

    thank so much

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...