Decimal.Implicit 運算子

定義

定義從某個類型值到 Decimal 值的隱含轉換。Defines an implicit conversion of the value of a type to a Decimal value.

多載

Implicit(UInt32 to Decimal)

定義從 32 位元不帶正負號整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 32-bit unsigned integer to a Decimal.

此應用程式開發介面不符合 CLS 標準。This API is not CLS-compliant.

Implicit(UInt16 to Decimal)

定義從 16 位元不帶正負號的整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 16-bit unsigned integer to a Decimal.

此應用程式開發介面不符合 CLS 標準。This API is not CLS-compliant.

Implicit(SByte to Decimal)

定義從 8 位元帶正負號的整數到 Decimal 的隱含轉換。Defines an implicit conversion of an 8-bit signed integer to a Decimal.

此應用程式開發介面不符合 CLS 標準。This API is not CLS-compliant.

Implicit(Int64 to Decimal)

定義從 64 位元帶正負號的整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 64-bit signed integer to a Decimal.

Implicit(Byte to Decimal)

定義從 8 位元不帶正負號整數到 Decimal 的隱含轉換。Defines an implicit conversion of an 8-bit unsigned integer to a Decimal.

Implicit(Int16 to Decimal)

定義從 16 位元帶正負號的整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 16-bit signed integer to a Decimal.

Implicit(Char to Decimal)

定義從 Unicode 字元到 Decimal 的隱含轉換。Defines an implicit conversion of a Unicode character to a Decimal.

Implicit(UInt64 to Decimal)

定義從 64 位元不帶正負號整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 64-bit unsigned integer to a Decimal.

此應用程式開發介面不符合 CLS 標準。This API is not CLS-compliant.

Implicit(Int32 to Decimal)

定義從 32 位元帶正負號的整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 32-bit signed integer to a Decimal.

備註

Implicit 方法的多載會定義編譯器可以自動轉換 Decimal 值的類型,而不需要明確轉換運算子(在中C#)或呼叫轉換函數(在 Visual Basic 中)。The overloads of the Implicit method define the types from which the compiler can automatically convert a Decimal value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). 它們是不涉及資料遺失,也不會擲回 OverflowException 例外狀況的擴輾轉換。They are widening conversions that do not involve data loss and do not throw an OverflowException exception.

Implicit(UInt32 to Decimal)

重要

此 API 不符合 CLS 規範。

定義從 32 位元不帶正負號整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 32-bit unsigned integer to a Decimal.

此應用程式開發介面不符合 CLS 標準。This API is not CLS-compliant.

public:
 static operator System::Decimal(System::UInt32 value);
[System.CLSCompliant(false)]
public static implicit operator decimal (uint value);
static member op_Implicit : uint32 -> decimal
Public Shared Widening Operator CType (value As UInteger) As Decimal

參數

value
UInt32

要轉換之 32 位元不帶正負號的整數。The 32-bit unsigned integer to convert.

傳回

轉換的 32 位元不帶正負號整數。The converted 32-bit unsigned integer.

屬性

範例

下列範例會將 UInt32 值轉換成 Decimal 數位。The following example converts UInt32 values to Decimal numbers.

using namespace System;

void main()
{
     // Define an array of 32-bit unsigned integer values.
     array<UInt32>^ values = { UInt32::MinValue, UInt32::MaxValue, 
                               0xFFFFFF, 123456789, 4000000000 };
     // Convert each value to a Decimal.
     for each (UInt32 value in values) {
        Decimal decValue = value;
        Console::WriteLine("{0} ({1}) --> {2} ({3})", value,
                          value.GetType()->Name, decValue,
                          decValue.GetType()->Name); 
     }                            
}
// The example displays the following output:
//       0 (UInt32) --> 0 (Decimal)
//       4294967295 (UInt32) --> 4294967295 (Decimal)
//       16777215 (UInt32) --> 16777215 (Decimal)
//       123456789 (UInt32) --> 123456789 (Decimal)
//       4000000000 (UInt32) --> 4000000000 (Decimal)
using System;

class Example
{
    public static void Main()
    {
        // Define an array of 32-bit unsigned integer values.
        uint[] values = { uint.MinValue, uint.MaxValue, 0xFFFFFF,
                          123456789, 4000000000 };
        // Convert each value to a Decimal.
        foreach (var value in values) {
           Decimal decValue = value;
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name);         
        }
    }
}
// The example displays the following output:
//       0 (UInt32) --> 0 (Decimal)
//       4294967295 (UInt32) --> 4294967295 (Decimal)
//       16777215 (UInt32) --> 16777215 (Decimal)
//       123456789 (UInt32) --> 123456789 (Decimal)
//       4000000000 (UInt32) --> 4000000000 (Decimal)
Module Example
    Public Sub Main()
        ' Define an array of 32-bit unsigned integer values.
        Dim values() As UInteger = { UInteger.MinValue, UInteger.MaxValue, 
                                     &hFFFFFF, 123456789, 4000000000 }
        For Each value In values
           Dim decValue As Decimal = value
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name)           
        Next   
    End Sub 
End Module
' The example displays the following output:
'       0 (UInt32) --> 0 (Decimal)
'       4294967295 (UInt32) --> 4294967295 (Decimal)
'       16777215 (UInt32) --> 16777215 (Decimal)
'       123456789 (UInt32) --> 123456789 (Decimal)
'       4000000000 (UInt32) --> 4000000000 (Decimal)

備註

Implicit 方法的多載會定義編譯器可以自動轉換 Decimal 值的類型,而不需要明確轉換運算子(在中C#)或呼叫轉換函數(在 Visual Basic 中)。The overloads of the Implicit method define the types from which the compiler can automatically convert a Decimal value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). 它們是不涉及資料遺失,也不會擲回 OverflowException 例外狀況的擴輾轉換。They are widening conversions that do not involve data loss and do not throw an OverflowException exception.

另請參閱

Implicit(UInt16 to Decimal)

重要

此 API 不符合 CLS 規範。

定義從 16 位元不帶正負號的整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 16-bit unsigned integer to a Decimal.

此應用程式開發介面不符合 CLS 標準。This API is not CLS-compliant.

public:
 static operator System::Decimal(System::UInt16 value);
[System.CLSCompliant(false)]
public static implicit operator decimal (ushort value);
static member op_Implicit : uint16 -> decimal
Public Shared Widening Operator CType (value As UShort) As Decimal

參數

value
UInt16

要轉換之 16 位元不帶正負號的整數。The 16-bit unsigned integer to convert.

傳回

轉換的 16 位元不帶正負號整數。The converted 16-bit unsigned integer.

屬性

範例

下列範例會將 UInt16 值轉換成 Decimal 數位。The following example converts UInt16 values to Decimal numbers.

using namespace System;

void main()
{
     // Define an array of 16-bit unsigned integer values.
     array<UInt16>^ values = { UInt16::MinValue, UInt16::MaxValue,     
                               0xFFF, 12345, 40000 };
     // Convert each value to a Decimal.
     for each (UInt16 value in values) {
        Decimal decValue = value;
        Console::WriteLine("{0} ({1}) --> {2} ({3})", value,
                           value.GetType()->Name, decValue,
                           decValue.GetType()->Name);         
     }
}
// The example displays the following output:
//       0 (UInt16) --> 0 (Decimal)
//       65535 (UInt16) --> 65535 (Decimal)
//       4095 (UInt16) --> 4095 (Decimal)
//       12345 (UInt16) --> 12345 (Decimal)
//       40000 (UInt16) --> 40000 (Decimal)
using System;

class Example
{
    public static void Main()
    {
        // Define an array of 16-bit unsigned integer values.
        ushort[] values = { ushort.MinValue, ushort.MaxValue,     
                            0xFFF, 12345, 40000 };
        // Convert each value to a Decimal.
        foreach (var value in values) {
           Decimal decValue = value;
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name);         
        }
    }
}
// The example displays the following output:
//       0 (UInt16) --> 0 (Decimal)
//       65535 (UInt16) --> 65535 (Decimal)
//       4095 (UInt16) --> 4095 (Decimal)
//       12345 (UInt16) --> 12345 (Decimal)
//       40000 (UInt16) --> 40000 (Decimal)
Module Example
    Public Sub Main()
        ' Define an array of 16-bit unsigned integer values.
        Dim values() As Decimal = { UShort.MinValue, UShort.MaxValue,     
                                    &hFFF, 12345, 40000 }
        ' Convert each value to a Decimal.
        For Each value In values
           Dim decValue As Decimal = value
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name)         
        Next
    End Sub 
End Module
' The example displays the following output:
'       0 (Decimal) --> 0 (Decimal)
'       65535 (Decimal) --> 65535 (Decimal)
'       4095 (Decimal) --> 4095 (Decimal)
'       12345 (Decimal) --> 12345 (Decimal)
'       40000 (Decimal) --> 40000 (Decimal)

備註

Implicit 方法的多載會定義編譯器可以自動轉換 Decimal 值的類型,而不需要明確轉換運算子(在中C#)或呼叫轉換函數(在 Visual Basic 中)。The overloads of the Implicit method define the types from which the compiler can automatically convert a Decimal value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). 它們是不涉及資料遺失,也不會擲回 OverflowException 例外狀況的擴輾轉換。They are widening conversions that do not involve data loss and do not throw an OverflowException exception.

另請參閱

Implicit(SByte to Decimal)

重要

此 API 不符合 CLS 規範。

定義從 8 位元帶正負號的整數到 Decimal 的隱含轉換。Defines an implicit conversion of an 8-bit signed integer to a Decimal.

此應用程式開發介面不符合 CLS 標準。This API is not CLS-compliant.

public:
 static operator System::Decimal(System::SByte value);
[System.CLSCompliant(false)]
public static implicit operator decimal (sbyte value);
static member op_Implicit : sbyte -> decimal
Public Shared Widening Operator CType (value As SByte) As Decimal

參數

value
SByte

要轉換的 8 位元帶正負號的整數。The 8-bit signed integer to convert.

傳回

轉換過的 8 位元帶正負號的整數。The converted 8-bit signed integer.

屬性

範例

下列範例會將 SByte 值轉換成 Decimal 數位。The following example converts SByte values to Decimal numbers.

using namespace System;

void main()
{
     // Define an array of 8-bit signed integer values.
     array<SByte>^ values = { SByte::MinValue, SByte::MaxValue,     
                              0x3F, 123, -100 };
     // Convert each value to a Decimal.
     for each (SByte value in values) {
        Decimal decValue = value;
        Console::WriteLine("{0} ({1}) --> {2} ({3})", value,
                          value.GetType()->Name, decValue,
                          decValue.GetType()->Name);         
     }
}
// The example displays the following output:
//       -128 (SByte) --> -128 (Decimal)
//       127 (SByte) --> 127 (Decimal)
//       63 (SByte) --> 63 (Decimal)
//       123 (SByte) --> 123 (Decimal)
//       -100 (SByte) --> -100 (Decimal)
using System;

class Example
{
    public static void Main()
    {
        // Define an array of 8-bit signed integer values.
        sbyte[] values = { sbyte.MinValue, sbyte.MaxValue,     
                           0x3F, 123, -100 };
        // Convert each value to a Decimal.
        foreach (var value in values) {
           Decimal decValue = value;
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name);         
        }
    }
}
// The example displays the following output:
//    -128 (SByte) --> -128 (Decimal)
//    127 (SByte) --> 127 (Decimal)
//    63 (SByte) --> 63 (Decimal)
//    123 (SByte) --> 123 (Decimal)
//    -100 (SByte) --> -100 (Decimal)
Module Example
    Public Sub Main()
        ' Define an array of 8-bit signed integer values.
        Dim values() As SByte = { SByte.MinValue, SByte.MaxValue,     
                                  &h3F, 123, -100 }
        ' Convert each value to a Decimal.
        For Each value In values
           Dim decValue As Decimal = value
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name)
        Next                         
    End Sub
End Module
' The example displays the following output:
'       -128 (SByte) --> -128 (Decimal)
'       127 (SByte) --> 127 (Decimal)
'       63 (SByte) --> 63 (Decimal)
'       123 (SByte) --> 123 (Decimal)
'       -100 (SByte) --> -100 (Decimal)

備註

Implicit 方法的多載會定義編譯器可以自動轉換 Decimal 值的類型,而不需要明確轉換運算子(在中C#)或呼叫轉換函數(在 Visual Basic 中)。The overloads of the Implicit method define the types from which the compiler can automatically convert a Decimal value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). 它們是不涉及資料遺失,也不會擲回 OverflowException 例外狀況的擴輾轉換。They are widening conversions that do not involve data loss and do not throw an OverflowException exception.

另請參閱

Implicit(Int64 to Decimal)

定義從 64 位元帶正負號的整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 64-bit signed integer to a Decimal.

public:
 static operator System::Decimal(long value);
public static implicit operator decimal (long value);
static member op_Implicit : int64 -> decimal
Public Shared Widening Operator CType (value As Long) As Decimal

參數

value
Int64

要轉換的 64 位元帶正負號的整數。The 64-bit signed integer to convert.

傳回

轉換過的 64 位元帶正負號的整數。The converted 64-bit signed integer.

範例

下列範例會將 Int64 值轉換成 Decimal 數位。The following example converts Int64 values to Decimal numbers.

using namespace System;

void main()
{
        // Define an array of 64-bit integer values.
        array<Int64>^ values = { Int64::MinValue, Int64::MaxValue, 
                                 0xFFFFFFFFFFFF, 123456789123456789,
                                 -1000000000000000 };
        // Convert each value to a Decimal.
        for each (Int64 value in values) {
           Decimal decValue = value;
           Console::WriteLine("{0} ({1}) --> {2} ({3})", value,
                              value.GetType()->Name, decValue,
                              decValue.GetType()->Name);         
        }
}
// The example displays the following output:
//    -9223372036854775808 (Int64) --> -9223372036854775808 (Decimal)
//    9223372036854775807 (Int64) --> 9223372036854775807 (Decimal)
//    281474976710655 (Int64) --> 281474976710655 (Decimal)
//    123456789123456789 (Int64) --> 123456789123456789 (Decimal)
//    -1000000000000000 (Int64) --> -1000000000000000 (Decimal)
using System;

class Example
{
    public static void Main()
    {
        // Define an array of 64-bit integer values.
        long[] values = { long.MinValue, long.MaxValue, 
                          0xFFFFFFFFFFFF, 123456789123456789,
                          -1000000000000000 };
        // Convert each value to a Decimal.
        foreach (var value in values) {
           Decimal decValue = value;
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name);         
        }
    }
}
// The example displays the following output:
//    -9223372036854775808 (Int64) --> -9223372036854775808 (Decimal)
//    9223372036854775807 (Int64) --> 9223372036854775807 (Decimal)
//    281474976710655 (Int64) --> 281474976710655 (Decimal)
//    123456789123456789 (Int64) --> 123456789123456789 (Decimal)
//    -1000000000000000 (Int64) --> -1000000000000000 (Decimal)
Module Example
    Public Sub Main()
        ' Define an array of 64-bit integer values.
        Dim values() As Long = { Long.MinValue, Long.MaxValue, 
                                 &hFFFFFFFFFFFF, 123456789123456789,
                                 -1000000000000000 }
        ' Convert each value to a Decimal.
        For Each value In values
           Dim decValue As Decimal = value
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name)
        Next
    End Sub 
End Module
' The example displays the following output:
'    -9223372036854775808 (Int64) --> -9223372036854775808 (Decimal)
'    9223372036854775807 (Int64) --> 9223372036854775807 (Decimal)
'    281474976710655 (Int64) --> 281474976710655 (Decimal)
'    123456789123456789 (Int64) --> 123456789123456789 (Decimal)
'    -1000000000000000 (Int64) --> -1000000000000000 (Decimal)

備註

Implicit 方法的多載會定義編譯器可以自動轉換 Decimal 值的類型,而不需要明確轉換運算子(在中C#)或呼叫轉換函數(在 Visual Basic 中)。The overloads of the Implicit method define the types from which the compiler can automatically convert a Decimal value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). 它們是不涉及資料遺失,也不會擲回 OverflowException 例外狀況的擴輾轉換。They are widening conversions that do not involve data loss and do not throw an OverflowException exception.

另請參閱

Implicit(Byte to Decimal)

定義從 8 位元不帶正負號整數到 Decimal 的隱含轉換。Defines an implicit conversion of an 8-bit unsigned integer to a Decimal.

public:
 static operator System::Decimal(System::Byte value);
public static implicit operator decimal (byte value);
static member op_Implicit : byte -> decimal
Public Shared Widening Operator CType (value As Byte) As Decimal

參數

value
Byte

要轉換之 8 位元不帶正負號的整數。The 8-bit unsigned integer to convert.

傳回

轉換的 8 位元不帶正負號整數。The converted 8-bit unsigned integer.

範例

下列範例會將 Byte 值轉換成 Decimal 數位。The following example converts Byte values to Decimal numbers.

using namespace System;

void main()
{
    // Define an array of byte values.
    array<Byte>^ values = { Byte::MinValue, Byte::MaxValue, 
                            0x3F, 123, 200 };   
    // Convert each value to a Decimal.
    for each (Byte value in values) {
        Decimal decValue = value;
        Console::WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType()->Name, decValue,
                             decValue.GetType()->Name);         
    }
}
// The example displays the following output:
//       0 (Byte) --> 0 (Decimal)
//       255 (Byte) --> 255 (Decimal)
//       63 (Byte) --> 63 (Decimal)
//       123 (Byte) --> 123 (Decimal)
//       200 (Byte) --> 200 (Decimal)
using System;

class Example
{
    public static void Main()
    {
        // Define an array of byte values.
        byte[] values = { byte.MinValue, byte.MaxValue, 
                          0x3F, 123, 200 };   
        // Convert each value to a Decimal.
        foreach (var value in values) {
           decimal decValue = value;
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name);         
        }
    }
}
// The example displays the following output:
//       0 (Byte) --> 0 (Decimal)
//       255 (Byte) --> 255 (Decimal)
//       63 (Byte) --> 63 (Decimal)
//       123 (Byte) --> 123 (Decimal)
//       200 (Byte) --> 200 (Decimal)
Module Example
    Public Sub Main
        ' Define an array of byte values.
        Dim values() As Byte = { Byte.MinValue, Byte.MaxValue, 
                                 &h3F, 123, 200 }   
        ' Convert each value to a Decimal.
        For Each value In values
           Dim decValue As Decimal = value
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name)                   
        Next   
    End Sub 
End Module
' The example displays the following output:
'       0 (Byte) --> 0 (Decimal)
'       255 (Byte) --> 255 (Decimal)
'       63 (Byte) --> 63 (Decimal)
'       123 (Byte) --> 123 (Decimal)
'       200 (Byte) --> 200 (Decimal)

備註

Implicit 方法的多載會定義編譯器可以自動轉換 Decimal 值的類型,而不需要明確轉換運算子(在中C#)或呼叫轉換函數(在 Visual Basic 中)。The overloads of the Implicit method define the types from which the compiler can automatically convert a Decimal value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). 它們是不涉及資料遺失,也不會擲回 OverflowException 例外狀況的擴輾轉換。They are widening conversions that do not involve data loss and do not throw an OverflowException exception.

另請參閱

Implicit(Int16 to Decimal)

定義從 16 位元帶正負號的整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 16-bit signed integer to a Decimal.

public:
 static operator System::Decimal(short value);
public static implicit operator decimal (short value);
static member op_Implicit : int16 -> decimal
Public Shared Widening Operator CType (value As Short) As Decimal

參數

value
Int16

要轉換的 16 位元帶正負號的整數。The 16-bit signed integer to convert.

傳回

轉換過的 16 位元帶正負號的整數。The converted 16-bit signed integer.

範例

下列範例會將 Int16 值轉換成 Decimal 數位。The following example converts Int16 values to Decimal numbers. 這項轉換需要 Visual Basic 中的 op_Implicit 運算子,但在C#和C++中則否。This conversion requires the op_Implicit operator in Visual Basic, but not in C# and C++.

using namespace System;

void main()
{
     // Define an array of 16-bit integer values.
     array<Int16>^ values = { Int16::MinValue, Int16::MaxValue, 
                              0xFFF, 12345, -10000 };   
     // Convert each value to a Decimal.
     for each (Int16 value in values) {
        Decimal decValue = value;
        Console::WriteLine("{0} ({1}) --> {2} ({3})", value,
                          value.GetType()->Name, decValue,
                          decValue.GetType()->Name);         
     }
}
// The example displays the following output:
//    -32768 (Int16) --> -32768 (Decimal)
//    32767 (Int16) --> 32767 (Decimal)
//    4095 (Int16) --> 4095 (Decimal)
//    12345 (Int16) --> 12345 (Decimal)
//    -10000 (Int16) --> -10000 (Decimal)
using System;

class Example
{
    public static void Main()
    {
        // Define an array of 16-bit integer values.
        short[] values = { short.MinValue, short.MaxValue, 
                           0xFFF, 12345, -10000 };   
        // Convert each value to a Decimal.
        foreach (var value in values) {
           Decimal decValue = value;
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name);         
        }
    }
}
// The example displays the following output:
//       -32768 (Int16) --> -32768 (Decimal)
//       32767 (Int16) --> 32767 (Decimal)
//       4095 (Int16) --> 4095 (Decimal)
//       12345 (Int16) --> 12345 (Decimal)
//       -10000 (Int16) --> -10000 (Decimal)
Module Example
    Public Sub Main()
        ' Define an array of 16-bit integer values.
        Dim values() As Short = { Short.MinValue, Short.MaxValue, 
                                  &hFFF, 12345, -10000 }   
        ' Convert each value to a Decimal.
        For Each value In values
           Dim decValue As Decimal = value
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name)         
        Next
    End Sub 
End Module
' The example displays the following output:
'    -32768 (Int16) --> -32768 (Decimal)
'    32767 (Int16) --> 32767 (Decimal)
'    4095 (Int16) --> 4095 (Decimal)
'    12345 (Int16) --> 12345 (Decimal)
'    -10000 (Int16) --> -10000 (Decimal)

備註

Implicit 方法的多載會定義編譯器可以自動轉換 Decimal 值的類型,而不需要明確轉換運算子(在中C#)或呼叫轉換函數(在 Visual Basic 中)。The overloads of the Implicit method define the types from which the compiler can automatically convert a Decimal value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). 它們是不涉及資料遺失,也不會擲回 OverflowException 例外狀況的擴輾轉換。They are widening conversions that do not involve data loss and do not throw an OverflowException exception.

另請參閱

Implicit(Char to Decimal)

定義從 Unicode 字元到 Decimal 的隱含轉換。Defines an implicit conversion of a Unicode character to a Decimal.

public:
 static operator System::Decimal(char value);
public static implicit operator decimal (char value);
static member op_Implicit : char -> decimal
Public Shared Widening Operator CType (value As Char) As Decimal

參數

value
Char

要轉換的 Unicode 字元。The Unicode character to convert.

傳回

轉換過的 Unicode 字元。The converted Unicode character.

範例

下列範例會將 Char 值(Unicode 字元)轉換成 Decimal 數位。The following example converts Char values (Unicode characters) to Decimal numbers. 這項轉換需要 Visual Basic 中的 op_Implicit 運算子,但在C#和C++中則否。This conversion requires the op_Implicit operator in Visual Basic, but not in C# and C++.

using namespace System;

void main()
{
     // Define an array of Char values.
     array<Char>^ values = { L'\0', L' ', L'*', L'A', L'a', 
                             L'{', L'Æ' };

     // Convert each Char value to a Decimal.
     for each (wchar_t value in values) {
        Decimal decValue = value;
        Console::WriteLine("'{0}' ({1}) --> {2} ({3})", value,
                           value.GetType()->Name, decValue,
                           decValue.GetType()->Name); 
     }    
}
// This example displays the following output:
//       ' ' (Decimal) --> 0 (Decimal)
//       ' ' (Decimal) --> 32 (Decimal)
//       '*' (Decimal) --> 42 (Decimal)
//       'A' (Decimal) --> 65 (Decimal)
//       'a' (Decimal) --> 97 (Decimal)
//       '{' (Decimal) --> 123 (Decimal)
//       'A' (Decimal) --> 195 (Decimal)
using System;

class Example
{
    public static void Main()
    {
        // Define an array of Char values.
        Char[] values = { '\0', ' ', '*', 'A', 'a', '{', 'Æ' };

        // Convert each Char value to a Decimal.
        foreach (var value in values) {
           decimal decValue = value;
           Console.WriteLine("'{0}' ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name);         
        }
    }
}
// The example displays the following output:
//       ' ' (Char) --> 0 (Decimal)
//       ' ' (Char) --> 32 (Decimal)
//       '*' (Char) --> 42 (Decimal)
//       'A' (Char) --> 65 (Decimal)
//       'a' (Char) --> 97 (Decimal)
//       '{' (Char) --> 123 (Decimal)
//       'Æ' (Char) --> 198 (Decimal)
Module Example
    Public Sub Main()
        ' Define an array of Char values.
        Dim values() As Char = { ChrW(0), " "c, "*"c, "A"c, "a"c, 
                                 "{"c, "Æ"c }

        ' Convert each Char value to a Decimal.
        For Each value In values
           Dim decValue As Decimal = Decimal.op_Implicit(value)
           Console.WriteLine("'{0}' ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name)      
        Next
    End Sub 
End Module
' The example displays the following output:
'       ' ' (Char) --> 0 (Decimal)
'       ' ' (Char) --> 32 (Decimal)
'       '*' (Char) --> 42 (Decimal)
'       'A' (Char) --> 65 (Decimal)
'       'a' (Char) --> 97 (Decimal)
'       '{' (Char) --> 123 (Decimal)
'       'Æ' (Char) --> 198 (Decimal)

備註

Implicit 方法的多載會定義編譯器可以自動轉換 Decimal 值的類型,而不需要明確轉換運算子(在中C#)或呼叫轉換函數(在 Visual Basic 中)。The overloads of the Implicit method define the types from which the compiler can automatically convert a Decimal value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). 它們是不涉及資料遺失,也不會擲回 OverflowException 例外狀況的擴輾轉換。They are widening conversions that do not involve data loss and do not throw an OverflowException exception.

另請參閱

Implicit(UInt64 to Decimal)

重要

此 API 不符合 CLS 規範。

定義從 64 位元不帶正負號整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 64-bit unsigned integer to a Decimal.

此應用程式開發介面不符合 CLS 標準。This API is not CLS-compliant.

public:
 static operator System::Decimal(System::UInt64 value);
[System.CLSCompliant(false)]
public static implicit operator decimal (ulong value);
static member op_Implicit : uint64 -> decimal
Public Shared Widening Operator CType (value As ULong) As Decimal

參數

value
UInt64

要轉換之 64 位元不帶正負號的整數。The 64-bit unsigned integer to convert.

傳回

轉換的 64 位元不帶正負號整數。The converted 64-bit unsigned integer.

屬性

範例

下列範例會使用 UInt64Decimal 轉換運算子,將 UInt64 值轉換成 Decimal 數位。The following example converts UInt64 values to Decimal numbers by using the UInt64 to Decimal conversion operator.

using namespace System;

void main()
{
     // Define an array of 64-bit unsigned integer values.
     array<UInt64>^ values = { UInt64::MinValue, UInt64::MaxValue, 
                               0xFFFFFFFFFFFF, 123456789123456789, 
                               1000000000000000 };
     // Convert each value to a Decimal.
     for each (UInt64 value in values) {
        Decimal decValue = value;
        Console::WriteLine("{0} ({1}) --> {2} ({3})", value,
                           value.GetType()->Name, decValue,
                           decValue.GetType()->Name);         
     }
}
// The example displays the following output:
//    0 (UInt64) --> 0 (Decimal)
//    18446744073709551615 (UInt64) --> 18446744073709551615 (Decimal)
//    281474976710655 (UInt64) --> 281474976710655 (Decimal)
//    123456789123456789 (UInt64) --> 123456789123456789 (Decimal)
//    1000000000000000 (UInt64) --> 1000000000000000 (Decimal)
using System;

public class Example
{
    public static void Main()
    {
        // Define an array of 64-bit unsigned integer values.
        ulong[] values = { ulong.MinValue, ulong.MaxValue, 
                           0xFFFFFFFFFFFF, 123456789123456789, 
                           1000000000000000 };
        // Convert each value to a Decimal.
        foreach (var value in values) {
           Decimal decValue = value;
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name);         
        }
    }
}
// The example displays the following output:
//    0 (UInt64) --> 0 (Decimal)
//    18446744073709551615 (UInt64) --> 18446744073709551615 (Decimal)
//    281474976710655 (UInt64) --> 281474976710655 (Decimal)
//    123456789123456789 (UInt64) --> 123456789123456789 (Decimal)
//    1000000000000000 (UInt64) --> 1000000000000000 (Decimal)
Module Example
    Public Sub Main()
        Dim values() As ULong = { ULong.MinValue, ULong.MaxValue, 
                           &hFFFFFFFFFFFF, 123456789123456789, 
                           1000000000000000 }
        For Each value In values
           Dim decValue As Decimal = value
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name)
        Next                              
    End Sub 
End Module
' The example displays the following output:
'    0 (UInt64) --> 0 (Decimal)
'    18446744073709551615 (UInt64) --> 18446744073709551615 (Decimal)
'    281474976710655 (UInt64) --> 281474976710655 (Decimal)
'    123456789123456789 (UInt64) --> 123456789123456789 (Decimal)
'    1000000000000000 (UInt64) --> 1000000000000000 (Decimal)

備註

Implicit 方法的多載會定義編譯器可以自動轉換 Decimal 值的類型,而不需要明確轉換運算子(在中C#)或呼叫轉換函數(在 Visual Basic 中)。The overloads of the Implicit method define the types from which the compiler can automatically convert a Decimal value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). 它們是不涉及資料遺失,也不會擲回 OverflowException 例外狀況的擴輾轉換。They are widening conversions that do not involve data loss and do not throw an OverflowException exception.

另請參閱

Implicit(Int32 to Decimal)

定義從 32 位元帶正負號的整數到 Decimal 的隱含轉換。Defines an implicit conversion of a 32-bit signed integer to a Decimal.

public:
 static operator System::Decimal(int value);
public static implicit operator decimal (int value);
static member op_Implicit : int -> decimal
Public Shared Widening Operator CType (value As Integer) As Decimal

參數

value
Int32

要轉換的 32 位元帶正負號的整數。The 32-bit signed integer to convert.

傳回

轉換過的 32 位元帶正負號的整數。The converted 32-bit signed integer.

範例

下列範例會將 Int32 值轉換成 Decimal 數位。The following example converts Int32 values to Decimal numbers.

using namespace System;

void main()
{
    // Define an array of 32-bit integer values.
    array<Int32>^ values = { Int32::MinValue, Int32::MaxValue, 
                             0xFFFFFF, 123456789, -1000000000 };
    // Convert each value to a Decimal.
    for each (Int32 value in values) {
        Decimal decValue = value;
        Console::WriteLine("{0} ({1}) --> {2} ({3})", value,
                          value.GetType()->Name, decValue,
                          decValue.GetType()->Name);
    }                               
}
// The example displays the following output:
//    -2147483648 (Int32) --> -2147483648 (Decimal)
//    2147483647 (Int32) --> 2147483647 (Decimal)
//    16777215 (Int32) --> 16777215 (Decimal)
//    123456789 (Int32) --> 123456789 (Decimal)
//    -1000000000 (Int32) --> -1000000000 (Decimal)
using System;

class Example
{
    public static void Main()
    {
        // Define an array of 32-bit integer values.
        int[] values = { int.MinValue, int.MaxValue, 0xFFFFFF,
                         123456789, -1000000000 };
        // Convert each value to a Decimal.
        foreach (var value in values) {
           Decimal decValue = value;
           Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                             value.GetType().Name, decValue,
                             decValue.GetType().Name);         
        }
    }
}
// The example displays the following output:
//    -2147483648 (Int32) --> -2147483648 (Decimal)
//    2147483647 (Int32) --> 2147483647 (Decimal)
//    16777215 (Int32) --> 16777215 (Decimal)
//    123456789 (Int32) --> 123456789 (Decimal)
//    -1000000000 (Int32) --> -1000000000 (Decimal)
Module Example
    Public Sub Main()
       ' Define an array of 32-bit integer values.
       Dim values() As Integer = { Integer.MinValue, Integer.MaxValue, 
                                   &hFFFFFF, 123456789, -1000000000 }
       ' Convert each value to a Decimal.
       For Each value In values
          Dim decValue As Decimal = value 
          Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                            value.GetType().Name, decValue,
                            decValue.GetType().Name)
       Next                     
    End Sub 
End Module
' The example displays the following output:
'       -2147483648 (Int32) --> -2147483648 (Decimal)
'       2147483647 (Int32) --> 2147483647 (Decimal)
'       16777215 (Int32) --> 16777215 (Decimal)
'       123456789 (Int32) --> 123456789 (Decimal)
'       -1000000000 (Int32) --> -1000000000 (Decimal)

備註

Implicit 方法的多載會定義編譯器可以自動轉換 Decimal 值的類型,而不需要明確轉換運算子(在中C#)或呼叫轉換函數(在 Visual Basic 中)。The overloads of the Implicit method define the types from which the compiler can automatically convert a Decimal value without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). 它們是不涉及資料遺失,也不會擲回 OverflowException 例外狀況的擴輾轉換。They are widening conversions that do not involve data loss and do not throw an OverflowException exception.

另請參閱

適用於