BigInteger in C# 4.0

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 .

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 .

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.

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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

One Response

  1. โหลดหนัง May 26, 2011 Reply
  2. BigInteger in C# | ProgramInDotnet August 8, 2011 Reply

Leave a Reply


Interesting BlogPosts to read

How to get an Enumerator from range of elements from ArrayList in C# ?
The code snippet shown in this blog post demonstrates how you can get the enumeraor from a range of ...
How to check for the column name in an SqlDataReader Object in C# ?
When working in ADO.NET for data access , there are times when you want to check to see if a column ...
Bing Search displays few school boards exam results
Looks like Bing now has a new feature that displays the results of various exams within Bing directl...