Aracılığıyla paylaş


BigInteger Constructor (Int32)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Sub New ( _
    value As Integer _
)
public BigInteger(
    int value
)

Parameters

Remarks

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.

Examples

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.

Dim integers() As Integer = { Int32.MinValue, -10534, -189, 0, 17, 113439,
                              Int32.MaxValue }
Dim constructed, assigned As BigInteger

For Each number As Integer In integers
   constructed = New BigInteger(number)
   assigned = number
   outputBlock.Text += String.Format("{0} = {1}: {2}", constructed, assigned,  
                     constructed.Equals(assigned)) + vbCrLf
Next
' 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
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;
   outputBlock.Text += String.Format("{0} = {1}: {2}", constructed, assigned,
                     constructed.Equals(assigned)) + "\n";
}
// 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      

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.