다음을 통해 공유


Decimal Implicit Conversion (SByte to Decimal)

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

Converts an 8-bit signed integer to a Decimal.

This API is not CLS-compliant. 

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

Syntax

'Declaration
Public Shared Widening Operator CType ( _
    value As SByte _
) As Decimal
public static implicit operator decimal (
    sbyte value
)

Parameters

Return Value

Type: System.Decimal
A Decimal that represents the converted 8-bit signed integer.

Examples

The following code example converts SByte values to Decimal numbers using the SByte to Decimal conversion. This conversion is implicit in C#, but requires the op_Implicit operator in Visual Basic and C++. Implicit conversions to Decimal use other methods in these languages.

' Example of the op_Implicit conversion from SByte to Decimal.
Imports System.Globalization

Module Example

   Const formatter As String = _
       "{0,15}{1,15}{2,10:X8}{3,9:X8}{4,9:X8}{5,9:X8}"

   ' Convert the SByte argument and display the Decimal value.
   Sub DecimalFromSByte(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal argument As SByte)

      Dim decValue As Decimal
      Dim bits() As Integer

      ' The compiler invokes a constructor in Visual Basic 
      ' unless op_Implicit is explicitly called.
      decValue = Decimal.op_Implicit(argument)

      ' Display the Decimal and its binary representation.
      bits = Decimal.GetBits(decValue)
      outputBlock.Text &= String.Format(formatter, argument, decValue, _
          bits(3), bits(2), bits(1), bits(0)) & vbCrLf
   End Sub

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

      outputBlock.Text &= String.Format( _
          "This example of the op_Implicit conversion from " & _
          "SByte to Decimal generates the " & vbCrLf & _
          "following output. It displays the Decimal value " & _
          "and its binary representation." & vbCrLf) & vbCrLf
      outputBlock.Text &= String.Format(formatter, "SByte argument", _
          "Decimal value", "bits(3)", "bits(2)", _
          "bits(1)", "bits(0)") & vbCrLf
      outputBlock.Text &= String.Format(formatter, "--------------", _
          "-------------", "-------", "-------", _
          "-------", "-------") & vbCrLf

      ' Convert SByte values and display the results.
      DecimalFromSByte(outputBlock, SByte.Parse("-128"))
      DecimalFromSByte(outputBlock, SByte.Parse("127"))
      DecimalFromSByte(outputBlock, SByte.Parse("3F", _
          NumberStyles.HexNumber))
      DecimalFromSByte(outputBlock, SByte.Parse("123"))
      DecimalFromSByte(outputBlock, SByte.Parse("-100"))
   End Sub
End Module

' This example of the op_Implicit conversion from SByte to Decimal generates the
' following output. It displays the Decimal value and its binary representation.
'
'  SByte argument  Decimal value   bits(3)  bits(2)  bits(1)  bits(0)
'  --------------  -------------   -------  -------  -------  -------
'            -128           -128  80000000 00000000 00000000 00000080
'             127            127  00000000 00000000 00000000 0000007F
'              63             63  00000000 00000000 00000000 0000003F
'             123            123  00000000 00000000 00000000 0000007B
'            -100           -100  80000000 00000000 00000000 00000064
// Example of the implicit conversion from sbyte to decimal.
using System;

class Example
{
   const string formatter =
       "{0,15}{1,15}{2,10:X8}{3,9:X8}{4,9:X8}{5,9:X8}";

   // Convert the sbyte argument and display the decimal value.
   public static void DecimalFromSByte(System.Windows.Controls.TextBlock outputBlock, sbyte argument)
   {
      decimal decValue;
      int[] bits;

      // Display the decimal and its binary representation.
      decValue = argument;
      bits = decimal.GetBits(decValue);

      outputBlock.Text += String.Format(formatter, argument, decValue,
          bits[3], bits[2], bits[1], bits[0]) + "\n";
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += String.Format(
          "This example of the implicit conversion from sbyte " +
          "to decimal generates the \nfollowing output. It " +
          "displays the decimal value and its binary " +
          "representation.\n") + "\n";
      outputBlock.Text += String.Format(formatter, "sbyte argument",
          "decimal value", "bits[3]", "bits[2]",
          "bits[1]", "bits[0]") + "\n";
      outputBlock.Text += String.Format(formatter, "--------------",
          "-------------", "-------", "-------",
          "-------", "-------") + "\n";

      // Convert sbyte values and display the results.
      DecimalFromSByte(outputBlock, sbyte.MinValue);
      DecimalFromSByte(outputBlock, sbyte.MaxValue);
      DecimalFromSByte(outputBlock, 0x3F);
      DecimalFromSByte(outputBlock, 123);
      DecimalFromSByte(outputBlock, -100);
   }
}

/*
This example of the implicit conversion from sbyte to decimal generates the
following output. It displays the decimal value and its binary representation.

 sbyte argument  decimal value   bits[3]  bits[2]  bits[1]  bits[0]
 --------------  -------------   -------  -------  -------  -------
           -128           -128  80000000 00000000 00000000 00000080
            127            127  00000000 00000000 00000000 0000007F
             63             63  00000000 00000000 00000000 0000003F
            123            123  00000000 00000000 00000000 0000007B
           -100           -100  80000000 00000000 00000000 00000064
*/

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.