Freigeben über


Decimal Constructor (UInt64)

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

Initializes a new instance of Decimal to the value of the specified 64-bit unsigned integer.

This API is not CLS-compliant. 

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

Syntax

'Declaration
<CLSCompliantAttribute(False)> _
Public Sub New ( _
    value As ULong _
)
[CLSCompliantAttribute(false)]
public Decimal(
    ulong value
)

Parameters

Examples

The following code example creates several Decimal numbers using the constructor overload that initializes a Decimal structure with a UInt64 value.

' Example of the Decimal( UInt64 ) constructor.

Module Example

   ' Create a Decimal object and display its value.
   Sub CreateDecimal(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal value As UInt64, ByVal valToStr As String)

      Dim decimalNum As New Decimal(value)

      ' Format the constructor for display.
      Dim ctor As String = _
          String.Format("Decimal( {0} )", valToStr)

      ' Display the constructor and its value.
      outputBlock.Text &= String.Format("{0,-33}{1,22}", ctor, decimalNum) & vbCrLf
   End Sub

   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      outputBlock.Text &= _
          "This example of the Decimal( UInt64 ) constructor " & _
          vbCrLf & "generates the following output." & vbCrLf & vbCrLf
      outputBlock.Text &= String.Format("{0,-33}{1,22}", "Constructor", "Value") & vbCrLf
      outputBlock.Text &= String.Format("{0,-33}{1,22}", "-----------", "-----") & vbCrLf

      ' Construct Decimal objects from UInt64 values.
      ' UInt64.MinValue and UInt64.MaxValue are not defined in VB.
      CreateDecimal(outputBlock, Convert.ToUInt64(0), """UInt64.MinValue""")
      CreateDecimal(outputBlock, Convert.ToUInt64(18446744073709551615D), _
          """UInt64.MaxValue""")
      CreateDecimal(outputBlock, Convert.ToUInt64(Long.MaxValue), _
          "Long.MaxValue")
      CreateDecimal(outputBlock, Convert.ToUInt64(999999999999999999), _
          "999999999999999999")
      CreateDecimal(outputBlock, Convert.ToUInt64(&H2000000000000000), _
          "&H2000000000000000")
      CreateDecimal(outputBlock, Convert.ToUInt64(1.6140901064495858E+19), _
          "16140901064495857664.0")
   End Sub
End Module

' This example of the Decimal( UInt64 ) constructor
' generates the following output.
' 
' Constructor                                       Value
' -----------                                       -----
' Decimal( "UInt64.MinValue" )                          0
' Decimal( "UInt64.MaxValue" )       18446744073709551615
' Decimal( Long.MaxValue )            9223372036854775807
' Decimal( 999999999999999999 )        999999999999999999
' Decimal( &H2000000000000000 )       2305843009213693952
' Decimal( 16140901064495857664.0 )  16140901064495857664
// Example of the decimal( ulong ) constructor.
using System;

class Example
{
   // Create a decimal object and display its value.
   public static void CreateDecimal(System.Windows.Controls.TextBlock outputBlock, ulong value, string valToStr)
   {
      decimal decimalNum = new decimal(value);

      // Format the constructor for display.
      string ctor = String.Format("decimal( {0} )", valToStr);

      // Display the constructor and its value.
      outputBlock.Text += String.Format("{0,-35}{1,22}", ctor, decimalNum) + "\n";
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "This example of the decimal( ulong ) " +
          "constructor \ngenerates the following output.\n" + "\n";
      outputBlock.Text += String.Format("{0,-35}{1,22}", "Constructor", "Value") + "\n";
      outputBlock.Text += String.Format("{0,-35}{1,22}", "-----------", "-----") + "\n";

      // Construct decimal objects from ulong values.
      CreateDecimal(outputBlock, ulong.MinValue, "ulong.MinValue");
      CreateDecimal(outputBlock, ulong.MaxValue, "ulong.MaxValue");
      CreateDecimal(outputBlock, long.MaxValue, "long.MaxValue");
      CreateDecimal(outputBlock, 999999999999999999, "999999999999999999");
      CreateDecimal(outputBlock, 0x2000000000000000, "0x2000000000000000");
      CreateDecimal(outputBlock, 0xE000000000000000, "0xE000000000000000");
   }
}

/*
This example of the decimal( ulong ) constructor
generates the following output.

Constructor                                         Value
-----------                                         -----
decimal( ulong.MinValue )                               0
decimal( ulong.MaxValue )            18446744073709551615
decimal( long.MaxValue )              9223372036854775807
decimal( 999999999999999999 )          999999999999999999
decimal( 0x2000000000000000 )         2305843009213693952
decimal( 0xE000000000000000 )        16140901064495857664
*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

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