Share via


BigInteger Constructor (UInt32)

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

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

This API is not CLS-compliant. The CLS-compliant alternative is BigInteger(Int64).

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

Syntax

'Declaration
<CLSCompliantAttribute(False)> _
Public Sub New ( _
    value As UInteger _
)
[CLSCompliantAttribute(false)]
public BigInteger(
    uint value
)

Parameters

Remarks

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

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

Examples

The following example uses the BigInteger(UInt32) constructor and an assignment statement to initialize BigInteger values from an array of unsigned 32-bit integers. It then compares the two values to demonstrate that the two methods of initializing a BigInteger value produce identical results.

Dim unsignedValues() As UInteger = {0, 16704, 199365, UInt32.MaxValue}
For Each unsignedValue As UInteger In unsignedValues
   Dim constructedNumber As New BigInteger(unsignedValue)
   Dim assignedNumber As BigInteger = unsignedValue
   If constructedNumber.Equals(assignedNumber) Then
      outputBlock.Text += String.Format("Both methods create a BigInteger whose value is {0}.", 
                        constructedNumber) + vbCrLf
   Else
      outputBlock.Text += String.Format("{0} ≠ {1}", constructedNumber, assignedNumber) + vbCrLf
   End If
Next
' The example displays the following output:
'    Both methods create a BigInteger whose value is 0.
'    Both methods create a BigInteger whose value is 16704.
'    Both methods create a BigInteger whose value is 199365.
'    Both methods create a BigInteger whose value is 4294967295.
uint[] unsignedValues = { 0, 16704, 199365, UInt32.MaxValue };
foreach (uint unsignedValue in unsignedValues)
{
   BigInteger constructedNumber = new BigInteger(unsignedValue);
   BigInteger assignedNumber = unsignedValue;
   if (constructedNumber.Equals(assignedNumber))
      outputBlock.Text += String.Format("Both methods create a BigInteger whose value is {0}.",
                        constructedNumber) + "\n";
   else
      outputBlock.Text += String.Format("{0} ≠ {1}", constructedNumber, assignedNumber) + "\n";

}
// The example displays the following output:
//    Both methods create a BigInteger whose value is 0.
//    Both methods create a BigInteger whose value is 16704.
//    Both methods create a BigInteger whose value is 199365.
//    Both methods create a BigInteger whose value is 4294967295.

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.