Export (0) Print
Expand All

BigInteger Constructor (Int32)

Initializes a new instance of the BigInteger structure using a 32-bit signed integer value.

Namespace:  System.Numerics
Assembly:  System.Numerics (in System.Numerics.dll)

public BigInteger(
	int value
)

Parameters

value
Type: System.Int32

A 32-bit signed integer.

There is no loss of precision when instantiating a BigInteger object by using this constructor.

The BigInteger value that results from calling this constructor is identical to the value that results from assigning an Int32 value to a BigInteger.

The BigInteger structure does not include constructors with a parameter of type Byte, Int16, SByte, or UInt16. However, the Int32 type supports the implicit conversion of 8-bit and 16-bit signed and unsigned integers to signed 32-bit integers. As a result, this constructor is called if value is any one of these four integral types.

The following example calls the BigInteger(Int32) constructor to instantiate BigInteger values from an array of 32-bit integers. It also uses implicit conversion to assign each 32-bit integer value to a BigInteger variable. It then compares the two values to establish that the resulting BigInteger values are the same.

int[] integers = { Int32.MinValue, -10534, -189, 0, 17, 113439,
                   Int32.MaxValue };
BigInteger constructed, assigned;

foreach (int number in integers)
{
   constructed = new BigInteger(number);
   assigned = number;
   Console.WriteLine("{0} = {1}: {2}", constructed, assigned, 
                     constructed.Equals(assigned)); 
}                                                  
// The example displays the following output: 
//       -2147483648 = -2147483648: True 
//       -10534 = -10534: True 
//       -189 = -189: True 
//       0 = 0: True 
//       17 = 17: True 
//       113439 = 113439: True 
//       2147483647 = 2147483647: True      

.NET Framework

Supported in: 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft