Jeevan Bhatt
Jeevan Bhatt

Reputation: 6101

What is BigInteger and when would we use that?

What is BigInteger and when would we use that ?

Upvotes: 1

Views: 3231

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1502656

It's a struct for an arbitrarily large integer, introduced in .NET 4.

You'd use it when you want to represent integers larger than Int64/UInt64 can cope with. For example, yesterday I wrote some code to normalize System.Decimal values. System.Decimal uses a 96-bit integer to represent its mantissa, but I wanted to work with it as an integer - so I used BigInteger.

(It's possible that I could have taken another approach just using decimal, but that's a different matter...)

As another example, there was a question asked just 45 minutes ago about representing large integers to work with them for cryptography purposes. While real crypto algorithms probably use something more specialized and efficient, using BigInteger to multiply large integers together etc is a good way of showing what logically happens in crypto code.

Upvotes: 4

RvdK
RvdK

Reputation: 19800

BigInteger on MSDN

The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds. The members of the BigInteger type closely parallel those of other integral types (the Byte, Int16, Int32, Int64, SByte, UInt16, UInt32, and UInt64 types). This type differs from the other integral types in the .NET Framework, which have a range indicated by their MinValue and MaxValue properties.

Upvotes: 1

Related Questions