UInt16 から Decimal への変換
16 ビット符号なし整数を Decimal に変換します。
この型変換は、CLS と互換性がありません。CLS との互換性に関する詳細については 「共通言語仕様の概要」 を参照してください。
<CLSCompliant(False)>
returnValue = Decimal.op_Implicit(value)
[C#]
[CLSCompliant(false)]
public static implicit operator decimal(ushortvalue);
[C++]
[CLSCompliant(false)]
public: static Decimal op_Implicit(unsigned shortvalue);
[JScript]
returnValue = value;
[Visual Basic] Visual Basic では、この型で定義されている型変換を使用することができます。ただし、独自に定義することはできません。
[JScript] JScript では、この型で定義されている型変換を使用することができます。ただし、独自に定義することはできません。
引数 [Visual Basic, JScript]
- value
16 ビット符号なし整数。
パラメータ [C#, C++]
- value
16 ビット符号なし整数。
戻り値
変換された 16 ビット符号なし整数を表す Decimal 。
使用例
[Visual Basic, C#, C++] UInt16 to Decimal 変換を使用して UInt16 の値を Decimal の数値に変換するコード例を次に示します。この変換は C# では暗黙で行われますが、Visual Basic および C++ では op_Implicit 演算子が必要です。これらの言語では、 Decimal への暗黙の変換には、他のメソッドが使用されます。
' Example of the op_Implicit conversion from UInt16 to Decimal.
Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic
Module DecimalFromUInt16Demo
Const formatter As String = _
"{0,15}{1,15}{2,10:X8}{3,9:X8}{4,9:X8}{5,9:X8}"
' Convert the UInt16 argument and display the Decimal value.
Sub DecimalFromUInt16( argument As UInt16 )
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 )
Console.WriteLine( formatter, argument, decValue, _
bits( 3 ), bits( 2 ), bits( 1 ), bits( 0 ) )
End Sub
Sub Main( )
Console.WriteLine( _
"This example of the op_Implicit conversion from " & _
"UInt16 to Decimal generates the " & vbCrLf & _
"following output. It displays the Decimal value " & _
"and its binary representation." & vbCrLf )
Console.WriteLine( formatter, "UInt16 argument", _
"Decimal value", "bits(3)", "bits(2)", _
"bits(1)", "bits(0)" )
Console.WriteLine( formatter, "---------------", _
"-------------", "-------", "-------", _
"-------", "-------" )
' Convert UInt16 values and display the results.
DecimalFromUInt16( UInt16.Parse( "0" ) )
DecimalFromUInt16( UInt16.Parse( "65535" ) )
DecimalFromUInt16( UInt16.Parse( "FFF", _
NumberStyles.HexNumber ) )
DecimalFromUInt16( UInt16.Parse( "12345" ) )
DecimalFromUInt16( UInt16.Parse( "40000" ) )
End Sub
End Module
' This example of the op_Implicit conversion from UInt16 to Decimal generates the
' following output. It displays the Decimal value and its binary representation.
'
' UInt16 argument Decimal value bits(3) bits(2) bits(1) bits(0)
' --------------- ------------- ------- ------- ------- -------
' 0 0 00000000 00000000 00000000 00000000
' 65535 65535 00000000 00000000 00000000 0000FFFF
' 4095 4095 00000000 00000000 00000000 00000FFF
' 12345 12345 00000000 00000000 00000000 00003039
' 40000 40000 00000000 00000000 00000000 00009C40
[C#]
// Example of the implicit conversion from ushort to decimal.
using System;
class DecimalFromUInt16Demo
{
const string formatter =
"{0,15}{1,15}{2,10:X8}{3,9:X8}{4,9:X8}{5,9:X8}";
// Convert the ushort argument and display the decimal value.
public static void DecimalFromUInt16( ushort argument )
{
decimal decValue;
int[ ] bits;
// Display the decimal and its binary representation.
decValue = argument;
bits = decimal.GetBits( decValue );
Console.WriteLine( formatter, argument, decValue,
bits[ 3 ], bits[ 2 ], bits[ 1 ], bits[ 0 ] );
}
public static void Main( )
{
Console.WriteLine(
"This example of the implicit conversion from ushort " +
"to decimal generates the \nfollowing output. It " +
"displays the decimal value and its binary " +
"representation.\n" );
Console.WriteLine( formatter, "ushort argument",
"decimal value", "bits[3]", "bits[2]",
"bits[1]", "bits[0]" );
Console.WriteLine( formatter, "---------------",
"-------------", "-------", "-------",
"-------", "-------" );
// Convert ushort values and display the results.
DecimalFromUInt16( ushort.MinValue );
DecimalFromUInt16( ushort.MaxValue );
DecimalFromUInt16( 0xFFF );
DecimalFromUInt16( 12345 );
DecimalFromUInt16( 40000 );
}
}
/*
This example of the implicit conversion from ushort to decimal generates the
following output. It displays the decimal value and its binary representation.
ushort argument decimal value bits[3] bits[2] bits[1] bits[0]
--------------- ------------- ------- ------- ------- -------
0 0 00000000 00000000 00000000 00000000
65535 65535 00000000 00000000 00000000 0000FFFF
4095 4095 00000000 00000000 00000000 00000FFF
12345 12345 00000000 00000000 00000000 00003039
40000 40000 00000000 00000000 00000000 00009C40
*/
[C++]
// Example of the op_Implicit conversion from unsigned short to Decimal.
#using <mscorlib.dll>
using namespace System;
const __wchar_t* formatter =
L"{0,14}{1,15}{2,10:X8}{3,9:X8}{4,9:X8}{5,9:X8}";
// Convert the unsigned short argument and display the Decimal value.
void DecimalFromUInt16( unsigned short argument )
{
Decimal decValue;
Int32 bits[ ];
// The compiler invokes a constructor in the Managed Extensions
// for C++ unless op_Implicit is explicitly called.
decValue = Decimal::op_Implicit( argument );
// Display the Decimal and its binary representation.
bits = Decimal::GetBits( decValue );
Console::WriteLine( formatter, __box( argument ),
__box( decValue ), __box( bits[ 3 ] ),
__box( bits[ 2 ] ), __box( bits[ 1 ] ), __box( bits[ 0 ] ) );
}
void main( )
{
Console::WriteLine(
S"This example of the op_Implicit conversion from unsigned "
S"short to Decimal \ngenerates the following output. "
S"It displays the Decimal value and its \nbinary "
S"representation.\n" );
Console::WriteLine( formatter, S"unsigned short",
S"Decimal value", S"bits[3]", S"bits[2]",
S"bits[1]", S"bits[0]" );
Console::WriteLine( formatter, S"--------------",
S"-------------", S"-------", S"-------",
S"-------", S"-------" );
// Convert unsigned short and display the results.
DecimalFromUInt16( UInt16::MinValue );
DecimalFromUInt16( UInt16::MaxValue );
DecimalFromUInt16( 0xFFF );
DecimalFromUInt16( 12345 );
DecimalFromUInt16( 40000 );
}
/*
This example of the op_Implicit conversion from unsigned short to Decimal
generates the following output. It displays the Decimal value and its
binary representation.
unsigned short Decimal value bits[3] bits[2] bits[1] bits[0]
-------------- ------------- ------- ------- ------- -------
0 0 00000000 00000000 00000000 00000000
65535 65535 00000000 00000000 00000000 0000FFFF
4095 4095 00000000 00000000 00000000 00000FFF
12345 12345 00000000 00000000 00000000 00003039
40000 40000 00000000 00000000 00000000 00009C40
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard