İngilizce dilinde oku

Aracılığıyla paylaş


Decimal.Explicit Operatör

Tanım

Bir nesne ile başka bir tür arasında açık bir Decimal dönüştürme tanımlar.

Aşırı Yüklemeler

Explicit(Single to Decimal)

Tek duyarlıklı kayan noktalı bir sayının öğesine açık bir Decimaldönüştürmesini tanımlar.

Explicit(Double to Decimal)

Çift duyarlıklı kayan noktalı bir sayının açık dönüştürmesini tanımlar Decimal.

Explicit(Decimal to UInt64)

öğesinin Decimal 64 bit işaretsiz tamsayıya açık bir dönüştürmesini tanımlar.

Bu API, CLS uyumlu değildir.

Explicit(Decimal to UInt32)

öğesinin Decimal 32 bit işaretsiz tamsayıya açık bir dönüştürmesini tanımlar.

Bu API, CLS uyumlu değildir.

Explicit(Decimal to UInt16)

öğesinin Decimal 16 bit işaretsiz tamsayıya açık bir dönüştürmesini tanımlar.

Bu API, CLS uyumlu değildir.

Explicit(Decimal to SByte)

öğesinin Decimal 8 bit imzalı tamsayıya açık dönüştürmesini tanımlar.

Bu API, CLS uyumlu değildir.

Explicit(Decimal to Single)

öğesinin tek duyarlıklı kayan Decimal noktalı sayıya açık bir dönüştürmesini tanımlar.

Explicit(Decimal to Int32)

öğesinin Decimal 32 bit imzalı tamsayıya açık bir dönüştürmesini tanımlar.

Explicit(Decimal to Int16)

bir öğesinin Decimal 16 bit imzalı tamsayıya açık bir dönüştürmesini tanımlar.

Explicit(Decimal to Double)

bir öğesinin çift duyarlıklı kayan Decimal noktalı sayıya açık bir dönüştürmesini tanımlar.

Explicit(Decimal to Char)

bir öğesinin Decimal Unicode karakterine açık bir dönüştürmesini tanımlar.

Explicit(Decimal to Byte)

öğesinin Decimal 8 bit işaretsiz tamsayıya açık bir dönüştürmesini tanımlar.

Explicit(Decimal to Int64)

64 bit imzalı tamsayıya açık bir dönüştürme Decimal tanımlar.

Explicit(Single to Decimal)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

Tek duyarlıklı kayan noktalı bir sayının öğesine açık bir Decimaldönüştürmesini tanımlar.

C#
public static explicit operator decimal (float value);

Parametreler

value
Single

Dönüştürülecek tek duyarlıklı kayan nokta sayısı.

Döndürülenler

Dönüştürülen tek duyarlıklı kayan nokta sayısı.

Özel durumlar

value Decimal.MaxValue değerinden büyük veya Decimal.MinValue değerinden küçüktür.

-veya-

value, PositiveInfinityveya NegativeInfinityşeklindedirNaN.

Örnekler

Aşağıdaki örnek, Single dönüştürme işlecini Single kullanarak değerleri Decimal sayılara Decimal dönüştürür. Bu dönüştürme için Visual Basic'teki op_Explicit işleci gerekir.

C#
// Example of the explicit conversion from float to decimal.
using System;

class DecimalFromSingleDemo
{
    const string formatter = "{0,16:E7}{1,33}";

    // Get the exception type name; remove the namespace prefix.
    public static string GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring(
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Convert the float argument; catch exceptions that are thrown.
    public static void DecimalFromSingle( float argument )
    {
        object decValue;

        // Convert the float argument to a decimal value.
        try
        {
            decValue = (decimal)argument;
        }
        catch( Exception ex )
        {
            decValue = GetExceptionType( ex );
        }

        Console.WriteLine( formatter, argument, decValue );
    }

    public static void Main( )
    {
        Console.WriteLine(
            "This example of the explicit conversion from float " +
            "to decimal \ngenerates the following output.\n" );
        Console.WriteLine( formatter, "float argument",
            "decimal value" );
        Console.WriteLine( formatter, "--------------",
            "-------------" );

        // Convert float values and display the results.
        DecimalFromSingle( 1.2345E-30F );
        DecimalFromSingle( 1.2345E-26F );
        DecimalFromSingle( 1.23456E-22F );
        DecimalFromSingle( 1.23456E-12F );
        DecimalFromSingle( 1.234567F );
        DecimalFromSingle( 1.234567E+12F );
        DecimalFromSingle( 1.2345678E+28F );
        DecimalFromSingle( 1.2345678E+30F );
    }
}

/*
This example of the explicit conversion from float to decimal
generates the following output.

  float argument                    decimal value
  --------------                    -------------
  1.2345000E-030                                0
  1.2345000E-026   0.0000000000000000000000000123
  1.2345600E-022    0.000000000000000000000123456
  1.2345600E-012              0.00000000000123456
  1.2345671E+000                         1.234567
  1.2345670E+012                    1234567000000
  1.2345678E+028    12345680000000000000000000000
  1.2345678E+030                OverflowException
*/

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Double to Decimal)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

Çift duyarlıklı kayan noktalı bir sayının açık dönüştürmesini tanımlar Decimal.

C#
public static explicit operator decimal (double value);

Parametreler

value
Double

Dönüştürülecek çift duyarlıklı kayan nokta sayısı.

Döndürülenler

Dönüştürülen çift duyarlıklı kayan nokta sayısı.

Özel durumlar

value Decimal.MaxValue değerinden büyük veya Decimal.MinValue değerinden küçüktür.

-veya-

value, PositiveInfinityveya NegativeInfinityşeklindedirNaN.

Örnekler

Aşağıdaki örnek, Double dönüştürme işlecini Double kullanarak değerleri Decimal sayılara Decimal dönüştürür. Bu dönüştürme için Visual Basic'teki op_Explicit işleci gerekir.

C#
// Example of the explicit conversion from double to decimal.
using System;

class DecimalFromDoubleDemo
{
    const string formatter = "{0,25:E16}{1,33}";

    // Get the exception type name; remove the namespace prefix.
    public static string GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring(
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Convert the double argument; catch exceptions that are thrown.
    public static void DecimalFromDouble( double argument )
    {
        object decValue;

        // Convert the double argument to a decimal value.
        try
        {
            decValue = (decimal)argument;
        }
        catch( Exception ex )
        {
            decValue = GetExceptionType( ex );
        }

        Console.WriteLine( formatter, argument, decValue );
    }

    public static void Main( )
    {
        Console.WriteLine(
            "This example of the explicit conversion from double " +
            "to decimal \ngenerates the following output.\n" );
        Console.WriteLine( formatter, "double argument",
            "decimal value" );
        Console.WriteLine( formatter, "---------------",
            "-------------" );

        // Convert double values and display the results.
        DecimalFromDouble( 1.234567890123E-30 );
        DecimalFromDouble( 1.2345678901234E-25 );
        DecimalFromDouble( 1.23456789012345E-20 );
        DecimalFromDouble( 1.234567890123456E-10 );
        DecimalFromDouble( 1.2345678901234567 );
        DecimalFromDouble( 1.23456789012345678E+12 );
        DecimalFromDouble( 1.234567890123456789E+28 );
        DecimalFromDouble( 1.234567890123456789E+30 );
    }
}

/*
This example of the explicit conversion from double to decimal
generates the following output.

          double argument                    decimal value
          ---------------                    -------------
  1.2345678901230000E-030                                0
  1.2345678901233999E-025   0.0000000000000000000000001235
  1.2345678901234499E-020   0.0000000000000000000123456789
  1.2345678901234560E-010       0.000000000123456789012346
  1.2345678901234567E+000                 1.23456789012346
  1.2345678901234568E+012                 1234567890123.46
  1.2345678901234568E+028    12345678901234600000000000000
  1.2345678901234569E+030                OverflowException
*/

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to UInt64)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

Önemli

Bu API, CLS uyumlu değildir.

öğesinin Decimal 64 bit işaretsiz tamsayıya açık bir dönüştürmesini tanımlar.

Bu API, CLS uyumlu değildir.

C#
[System.CLSCompliant(false)]
public static explicit operator ulong (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden 64 bit işaretsiz tamsayı.

Öznitelikler

Özel durumlar

value UInt64.MaxValue değerinden negatif veya daha büyük.

Örnekler

Aşağıdaki örnek, Decimal açık ton UInt64 dönüştürme işlecini kullanarak sayıları değerlere UInt64Decimal dönüştürür.

C#
// Example of the explicit conversions from decimal to long and
// decimal to ulong.
using System;

class DecimalToU_Int64Demo
{
    const string formatter = "{0,25}{1,22}{2,22}";

    // Get the exception type name; remove the namespace prefix.
    public static string GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring(
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Convert the decimal argument; catch exceptions that are thrown.
    public static void DecimalToU_Int64( decimal argument )
    {
        object Int64Value;
        object UInt64Value;

        // Convert the argument to a long value.
        try
        {
            Int64Value = (long)argument;
        }
        catch( Exception ex )
        {
            Int64Value = GetExceptionType( ex );
        }

        // Convert the argument to a ulong value.
        try
        {
            UInt64Value = (ulong)argument;
        }
        catch( Exception ex )
        {
            UInt64Value = GetExceptionType( ex );
        }

        Console.WriteLine( formatter, argument,
            Int64Value, UInt64Value );
    }

    public static void Main( )
    {
        Console.WriteLine(
            "This example of the explicit conversions from decimal " +
            "to long \nand decimal to ulong generates the following " +
            "output. It displays \nseveral converted decimal " +
            "values.\n" );
        Console.WriteLine( formatter, "decimal argument",
            "long/exception", "ulong/exception" );
        Console.WriteLine( formatter, "----------------",
            "--------------", "---------------" );

        // Convert decimal values and display the results.
        DecimalToU_Int64( 123M );
        DecimalToU_Int64( new decimal( 123000, 0, 0, false, 3 ) );
        DecimalToU_Int64( 123.999M );
        DecimalToU_Int64( 18446744073709551615.999M );
        DecimalToU_Int64( 18446744073709551616M );
        DecimalToU_Int64( 9223372036854775807.999M );
        DecimalToU_Int64( 9223372036854775808M );
        DecimalToU_Int64( - 0.999M );
        DecimalToU_Int64( - 1M );
        DecimalToU_Int64( - 9223372036854775808.999M );
        DecimalToU_Int64( - 9223372036854775809M );
    }
}

/*
This example of the explicit conversions from decimal to long
and decimal to ulong generates the following output. It displays
several converted decimal values.

         decimal argument        long/exception       ulong/exception
         ----------------        --------------       ---------------
                      123                   123                   123
                  123.000                   123                   123
                  123.999                   123                   123
 18446744073709551615.999     OverflowException  18446744073709551615
     18446744073709551616     OverflowException     OverflowException
  9223372036854775807.999   9223372036854775807   9223372036854775807
      9223372036854775808     OverflowException   9223372036854775808
                   -0.999                     0                     0
                       -1                    -1     OverflowException
 -9223372036854775808.999  -9223372036854775808     OverflowException
     -9223372036854775809     OverflowException     OverflowException
*/

Açıklamalar

Bu işleç, açık dönüştürmeyi DecimalUInt64destekler. Bu tür açık dönüştürmelerin sözdizimi dile bağlıdır ve ayrı dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir. Örnek, C# ve Visual Basic kullanarak bir değeri açıkça bir DecimalUInt64 değere dönüştürdüğünüzde farklı dönüş değerlerini gösterir. Dilden bağımsız bir dönüştürme gerçekleştirmek için veya Convert.ToUInt64(Decimal) yöntemini çağırabilirsinizDecimal.ToUInt64(Decimal).

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to UInt32)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

Önemli

Bu API, CLS uyumlu değildir.

CLS uyumlu alternatif
System.Decimal.ToInt64(Decimal)

öğesinin Decimal 32 bit işaretsiz tamsayıya açık bir dönüştürmesini tanımlar.

Bu API, CLS uyumlu değildir.

C#
[System.CLSCompliant(false)]
public static explicit operator uint (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden 32 bit işaretsiz tamsayı.

Öznitelikler

Özel durumlar

Örnekler

Aşağıdaki örnek, Decimal açık ton UInt32 dönüştürme işlecini kullanarak sayıları değerlere UInt32Decimal dönüştürür.

C#
// Example of the explicit conversions from decimal to int and
// decimal to uint.
using System;

class DecimalToU_Int32Demo
{
    const string formatter = "{0,17}{1,19}{2,19}";

    // Get the exception type name; remove the namespace prefix.
    public static string GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring(
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Convert the decimal argument; catch exceptions that are thrown.
    public static void DecimalToU_Int32( decimal argument )
    {
        object Int32Value;
        object UInt32Value;

        // Convert the argument to an int value.
        try
        {
            Int32Value = (int)argument;
        }
        catch( Exception ex )
        {
            Int32Value = GetExceptionType( ex );
        }

        // Convert the argument to a uint value.
        try
        {
            UInt32Value = (uint)argument;
        }
        catch( Exception ex )
        {
            UInt32Value = GetExceptionType( ex );
        }

        Console.WriteLine( formatter, argument,
            Int32Value, UInt32Value );
    }

    public static void Main( )
    {
        Console.WriteLine(
            "This example of the explicit conversions from decimal " +
            "to int \nand decimal to uint generates the following " +
            "output. It displays \nseveral converted decimal " +
            "values.\n" );
        Console.WriteLine( formatter, "decimal argument",
            "int/exception", "uint/exception" );
        Console.WriteLine( formatter, "----------------",
            "-------------", "--------------" );

        // Convert decimal values and display the results.
        DecimalToU_Int32( 123M );
        DecimalToU_Int32( new decimal( 123000, 0, 0, false, 3 ) );
        DecimalToU_Int32( 123.999M );
        DecimalToU_Int32( 4294967295.999M );
        DecimalToU_Int32( 4294967296M );
        DecimalToU_Int32( 2147483647.999M );
        DecimalToU_Int32( 2147483648M );
        DecimalToU_Int32( - 0.999M );
        DecimalToU_Int32( - 1M );
        DecimalToU_Int32( - 2147483648.999M );
        DecimalToU_Int32( - 2147483649M );
    }
}

/*
This example of the explicit conversions from decimal to int
and decimal to uint generates the following output. It displays
several converted decimal values.

 decimal argument      int/exception     uint/exception
 ----------------      -------------     --------------
              123                123                123
          123.000                123                123
          123.999                123                123
   4294967295.999  OverflowException         4294967295
       4294967296  OverflowException  OverflowException
   2147483647.999         2147483647         2147483647
       2147483648  OverflowException         2147483648
           -0.999                  0                  0
               -1                 -1  OverflowException
  -2147483648.999        -2147483648  OverflowException
      -2147483649  OverflowException  OverflowException
*/

Açıklamalar

Bu işleç, açık dönüştürmeyi DecimalUInt32destekler. Bu tür açık dönüştürmelerin sözdizimi dile bağlıdır ve ayrı dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir. Örnek, C# ve Visual Basic kullanarak bir değeri açıkça bir DecimalUInt32 değere dönüştürdüğünüzde farklı dönüş değerlerini gösterir. Dilden bağımsız bir dönüştürme gerçekleştirmek için veya Convert.ToUInt32(Decimal) yöntemini çağırabilirsinizDecimal.ToUInt32(Decimal).

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to UInt16)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

Önemli

Bu API, CLS uyumlu değildir.

öğesinin Decimal 16 bit işaretsiz tamsayıya açık bir dönüştürmesini tanımlar.

Bu API, CLS uyumlu değildir.

C#
[System.CLSCompliant(false)]
public static explicit operator ushort (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden 16 bit işaretsiz tamsayı.

Öznitelikler

Özel durumlar

value UInt16.MinValue değerinden küçük veya UInt16.MaxValue değerinden büyük.

Örnekler

Aşağıdaki örnek, Decimal açık ton UInt16 dönüştürme işlecini kullanarak sayıları değerlere UInt16Decimal dönüştürür.

C#
// Example of the explicit conversions from decimal to short and
// decimal to ushort.
using System;

class DecimalToU_Int16Demo
{
    const string formatter = "{0,16}{1,19}{2,19}";

    // Get the exception type name; remove the namespace prefix.
    public static string GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring(
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Convert the decimal argument; catch exceptions that are thrown.
    public static void DecimalToU_Int16( decimal argument )
    {
        object Int16Value;
        object UInt16Value;

        // Convert the argument to a short value.
        try
        {
            Int16Value = (short)argument;
        }
        catch( Exception ex )
        {
            Int16Value = GetExceptionType( ex );
        }

        // Convert the argument to a ushort value.
        try
        {
            UInt16Value = (ushort)argument;
        }
        catch( Exception ex )
        {
            UInt16Value = GetExceptionType( ex );
        }

        Console.WriteLine( formatter, argument,
            Int16Value, UInt16Value );
    }

    public static void Main( )
    {
        Console.WriteLine(
            "This example of the explicit conversions from decimal " +
            "to short \nand decimal to ushort generates the " +
            "following output. It displays \nseveral converted " +
            "decimal values.\n" );
        Console.WriteLine( formatter, "decimal argument",
            "short/exception", "ushort/exception" );
        Console.WriteLine( formatter, "----------------",
            "---------------", "----------------" );

        // Convert decimal values and display the results.
        DecimalToU_Int16( 123M );
        DecimalToU_Int16( new decimal( 123000, 0, 0, false, 3 ) );
        DecimalToU_Int16( 123.999M );
        DecimalToU_Int16( 65535.999M );
        DecimalToU_Int16( 65536M );
        DecimalToU_Int16( 32767.999M );
        DecimalToU_Int16( 32768M );
        DecimalToU_Int16( - 0.999M );
        DecimalToU_Int16( - 1M );
        DecimalToU_Int16( - 32768.999M );
        DecimalToU_Int16( - 32769M );
    }
}

/*
This example of the explicit conversions from decimal to short
and decimal to ushort generates the following output. It displays
several converted decimal values.

decimal argument    short/exception   ushort/exception
----------------    ---------------   ----------------
             123                123                123
         123.000                123                123
         123.999                123                123
       65535.999  OverflowException              65535
           65536  OverflowException  OverflowException
       32767.999              32767              32767
           32768  OverflowException              32768
          -0.999                  0                  0
              -1                 -1  OverflowException
      -32768.999             -32768  OverflowException
          -32769  OverflowException  OverflowException
*/

Açıklamalar

Bu işleç, açık dönüştürmeyi DecimalUInt16destekler. Bu tür açık dönüştürmelerin sözdizimi dile bağlıdır ve ayrı dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir. Örnek, C# ve Visual Basic kullanarak bir değeri açıkça bir DecimalUInt16 değere dönüştürdüğünüzde farklı dönüş değerlerini gösterir. Dilden bağımsız bir dönüştürme gerçekleştirmek için veya Convert.ToUInt16(Decimal) yöntemini çağırabilirsinizDecimal.ToUInt16(Decimal).

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to SByte)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

Önemli

Bu API, CLS uyumlu değildir.

CLS uyumlu alternatif
System.Decimal.ToInt16(Decimal)

öğesinin Decimal 8 bit imzalı tamsayıya açık dönüştürmesini tanımlar.

Bu API, CLS uyumlu değildir.

C#
[System.CLSCompliant(false)]
public static explicit operator sbyte (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden 8 bit imzalı tamsayı.

Öznitelikler

Özel durumlar

value SByte.MinValue değerinden küçük veya SByte.MaxValue değerinden büyük.

Örnekler

Aşağıdaki örnek, Decimal açık ton SByte dönüştürme işlecini kullanarak sayıları değerlere SByteDecimal dönüştürür.

C#
using System;

class Example
{
    public static void Main()
    {
        // Define an array of decimal values.
       decimal[] values = { 78m, new Decimal(78000, 0, 0, false, 3),
                            78.999m, 255.999m, 256m, 127.999m,
                            128m, -0.999m, -1m, -128.999m, -129m };
       foreach (var value in values) {
          try {
              SByte byteValue = (SByte) value;
              Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                                value.GetType().Name, byteValue,
                                byteValue.GetType().Name);
           }
           catch (OverflowException) {
              Console.WriteLine("OverflowException: Cannot convert {0}",
                                value);
           }
       }
    }
}
// The example displays the following output:
//       78 (Decimal) --> 78 (SByte)
//       78.000 (Decimal) --> 78 (SByte)
//       78.999 (Decimal) --> 78 (SByte)
//       OverflowException: Cannot convert 255.999
//       OverflowException: Cannot convert 256
//       127.999 (Decimal) --> 127 (SByte)
//       OverflowException: Cannot convert 128
//       -0.999 (Decimal) --> 0 (SByte)
//       -1 (Decimal) --> -1 (SByte)
//       -128.999 (Decimal) --> -128 (SByte)
//       OverflowException: Cannot convert -129

Açıklamalar

Bu işleç, açık dönüştürmeyi DecimalSBytedestekler. Bu tür açık dönüştürmelerin sözdizimi dile bağlıdır ve ayrı dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir. Örnek, C# ve Visual Basic kullanarak bir Decimal değeri ve SByte değerine Byte açıkça dönüştürdüğünüzde farklı dönüş değerlerini gösterir. Dilden bağımsız bir dönüştürme gerçekleştirmek için yöntemini veya Convert.ToSByte(Decimal) yöntemini çağırabilirsinizDecimal.ToSByte(Decimal).

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to Single)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

bir öğesinin tek duyarlıklı kayan Decimal noktalı sayıya açık dönüştürmesini tanımlar.

C#
public static explicit operator float (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden tek duyarlıklı kayan noktalı sayı.

Örnekler

Aşağıdaki örnek, Decimal açık ton Single dönüştürme işlecini kullanarak sayıları değerlere SingleDecimal dönüştürür.

C#
using System;

class Example
{
    public static void Main( )
    {
        // Define an array of decimal values.
        decimal[] values = { 0.0000000000000000000000000001M,
                             0.0000000000123456789123456789M,
                             123M, new decimal(123000000, 0, 0, false, 6),
                             123456789.123456789M,
                             123456789123456789123456789M,
                             decimal.MinValue, decimal.MaxValue };
        // Convert each value to a double.
        foreach (var value in values) {
            float dblValue = (float) value;
            Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                              value.GetType().Name, dblValue,
                              dblValue.GetType().Name);
       }
    }
}
// The example displays the following output:
//    0.0000000000000000000000000001 (Decimal) --> 1E-28 (Single)
//    0.0000000000123456789123456789 (Decimal) --> 1.234568E-11 (Single)
//    123 (Decimal) --> 123 (Single)
//    123.000000 (Decimal) --> 123 (Single)
//    123456789.123456789 (Decimal) --> 1.234568E+08 (Single)
//    123456789123456789123456789 (Decimal) --> 1.234568E+26 (Single)
//    -79228162514264337593543950335 (Decimal) --> -7.922816E+28 (Single)
//    79228162514264337593543950335 (Decimal) --> 7.922816E+28 (Single)

Açıklamalar

Tek duyarlıklı kayan nokta sayısının bir değerinden daha az anlamlı basamağı olduğundan bu işlem duyarlık kaybına Decimalneden olabilir.

Bu işleç, öğesinin Decimal öğesine açık olarak dönüştürülmesini Singledestekler. Bu tür açık dönüştürmelerin sözdizimi dile bağlıdır ve ayrı dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir. Örnek, C# ve Visual Basic kullanarak bir değeri açıkça bir DecimalSingle değere dönüştürdüğünüzde farklı dönüş değerlerini gösterir. Dilden bağımsız bir dönüştürme gerçekleştirmek için veya Convert.ToSingle(Decimal) yöntemini çağırabilirsinizDecimal.ToSingle(Decimal).

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to Int32)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

32 bit imzalı tamsayıya açık bir Decimal dönüşüm tanımlar.

C#
public static explicit operator int (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden 32 bit işaretli tamsayı.

Özel durumlar

value Int32.MinValue değerinden küçük veya Int32.MaxValue değerinden büyük.

Örnekler

Aşağıdaki örnek, açık Decimal ton Int32 dönüştürme işlecini kullanarak sayıları değerlere Int32 dönüştürürDecimal.

C#
// Example of the explicit conversions from decimal to int and
// decimal to uint.
using System;

class DecimalToU_Int32Demo
{
    const string formatter = "{0,17}{1,19}{2,19}";

    // Get the exception type name; remove the namespace prefix.
    public static string GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring(
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Convert the decimal argument; catch exceptions that are thrown.
    public static void DecimalToU_Int32( decimal argument )
    {
        object Int32Value;
        object UInt32Value;

        // Convert the argument to an int value.
        try
        {
            Int32Value = (int)argument;
        }
        catch( Exception ex )
        {
            Int32Value = GetExceptionType( ex );
        }

        // Convert the argument to a uint value.
        try
        {
            UInt32Value = (uint)argument;
        }
        catch( Exception ex )
        {
            UInt32Value = GetExceptionType( ex );
        }

        Console.WriteLine( formatter, argument,
            Int32Value, UInt32Value );
    }

    public static void Main( )
    {
        Console.WriteLine(
            "This example of the explicit conversions from decimal " +
            "to int \nand decimal to uint generates the following " +
            "output. It displays \nseveral converted decimal " +
            "values.\n" );
        Console.WriteLine( formatter, "decimal argument",
            "int/exception", "uint/exception" );
        Console.WriteLine( formatter, "----------------",
            "-------------", "--------------" );

        // Convert decimal values and display the results.
        DecimalToU_Int32( 123M );
        DecimalToU_Int32( new decimal( 123000, 0, 0, false, 3 ) );
        DecimalToU_Int32( 123.999M );
        DecimalToU_Int32( 4294967295.999M );
        DecimalToU_Int32( 4294967296M );
        DecimalToU_Int32( 2147483647.999M );
        DecimalToU_Int32( 2147483648M );
        DecimalToU_Int32( - 0.999M );
        DecimalToU_Int32( - 1M );
        DecimalToU_Int32( - 2147483648.999M );
        DecimalToU_Int32( - 2147483649M );
    }
}

/*
This example of the explicit conversions from decimal to int
and decimal to uint generates the following output. It displays
several converted decimal values.

 decimal argument      int/exception     uint/exception
 ----------------      -------------     --------------
              123                123                123
          123.000                123                123
          123.999                123                123
   4294967295.999  OverflowException         4294967295
       4294967296  OverflowException  OverflowException
   2147483647.999         2147483647         2147483647
       2147483648  OverflowException         2147483648
           -0.999                  0                  0
               -1                 -1  OverflowException
  -2147483648.999        -2147483648  OverflowException
      -2147483649  OverflowException  OverflowException
*/

Açıklamalar

Bu işleç, öğesinin Decimal öğesine açık olarak dönüştürülmesini Int32destekler. Bu tür açık dönüştürmelerin sözdizimi dile bağlıdır ve ayrı dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir. Örnek, C#, C++ ve Visual Basic kullanarak bir Decimal değeri açıkça bir Int32 değere dönüştürdüğünüzde farklı dönüş değerlerini gösterir. Dilden bağımsız bir dönüştürme gerçekleştirmek için veya Convert.ToInt32(Decimal) yöntemini çağırabilirsinizDecimal.ToInt32(Decimal).

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to Int16)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

öğesinin Decimal 16 bit işaretli tamsayıya açık dönüştürmesini tanımlar.

C#
public static explicit operator short (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden 16 bit imzalı tamsayı.

Özel durumlar

value Int16.MinValue değerinden küçük veya Int16.MaxValue değerinden büyük.

Örnekler

Aşağıdaki örnek, açık Decimal ton Int16 dönüştürme işlecini kullanarak sayıları değerlere Int16 dönüştürürDecimal.

C#
// Example of the explicit conversions from decimal to short and
// decimal to ushort.
using System;

class DecimalToU_Int16Demo
{
    const string formatter = "{0,16}{1,19}{2,19}";

    // Get the exception type name; remove the namespace prefix.
    public static string GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring(
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Convert the decimal argument; catch exceptions that are thrown.
    public static void DecimalToU_Int16( decimal argument )
    {
        object Int16Value;
        object UInt16Value;

        // Convert the argument to a short value.
        try
        {
            Int16Value = (short)argument;
        }
        catch( Exception ex )
        {
            Int16Value = GetExceptionType( ex );
        }

        // Convert the argument to a ushort value.
        try
        {
            UInt16Value = (ushort)argument;
        }
        catch( Exception ex )
        {
            UInt16Value = GetExceptionType( ex );
        }

        Console.WriteLine( formatter, argument,
            Int16Value, UInt16Value );
    }

    public static void Main( )
    {
        Console.WriteLine(
            "This example of the explicit conversions from decimal " +
            "to short \nand decimal to ushort generates the " +
            "following output. It displays \nseveral converted " +
            "decimal values.\n" );
        Console.WriteLine( formatter, "decimal argument",
            "short/exception", "ushort/exception" );
        Console.WriteLine( formatter, "----------------",
            "---------------", "----------------" );

        // Convert decimal values and display the results.
        DecimalToU_Int16( 123M );
        DecimalToU_Int16( new decimal( 123000, 0, 0, false, 3 ) );
        DecimalToU_Int16( 123.999M );
        DecimalToU_Int16( 65535.999M );
        DecimalToU_Int16( 65536M );
        DecimalToU_Int16( 32767.999M );
        DecimalToU_Int16( 32768M );
        DecimalToU_Int16( - 0.999M );
        DecimalToU_Int16( - 1M );
        DecimalToU_Int16( - 32768.999M );
        DecimalToU_Int16( - 32769M );
    }
}

/*
This example of the explicit conversions from decimal to short
and decimal to ushort generates the following output. It displays
several converted decimal values.

decimal argument    short/exception   ushort/exception
----------------    ---------------   ----------------
             123                123                123
         123.000                123                123
         123.999                123                123
       65535.999  OverflowException              65535
           65536  OverflowException  OverflowException
       32767.999              32767              32767
           32768  OverflowException              32768
          -0.999                  0                  0
              -1                 -1  OverflowException
      -32768.999             -32768  OverflowException
          -32769  OverflowException  OverflowException
*/

Açıklamalar

Bu işleç, öğesinin Decimal öğesine açık olarak dönüştürülmesini Int16destekler. Bu tür açık dönüştürmelerin sözdizimi dile bağlıdır ve ayrı dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir. Örnek, C#, Visual Basic ve C++ kullanarak bir Decimal değeri bir değere Int16 açıkça dönüştürdüğünüzde farklı dönüş değerlerini gösterir. Dilden bağımsız bir dönüştürme gerçekleştirmek için veya Convert.ToInt16(Decimal) yöntemini çağırabilirsinizDecimal.ToInt16(Decimal).

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to Double)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

bir öğesinin çift duyarlıklı kayan Decimal noktalı sayıya açık dönüştürmesini tanımlar.

C#
public static explicit operator double (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden çift duyarlıklı kayan noktalı sayı.

Örnekler

Aşağıdaki örnek, açık Decimal ton Double dönüştürme işlecini kullanarak sayıları değerlere Double dönüştürürDecimal.

C#
using System;

class Example
{
    public static void Main( )
    {
        // Define an array of decimal values.
        decimal[] values = { 0.0000000000000000000000000001M,
                             0.0000000000123456789123456789M,
                             123M, new decimal(123000000, 0, 0, false, 6),
                             123456789.123456789M,
                             123456789123456789123456789M,
                             decimal.MinValue, decimal.MaxValue };
        // Convert each value to a double.
        foreach (var value in values) {
            double dblValue = (double) value;
            Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                              value.GetType().Name, dblValue,
                              dblValue.GetType().Name);
       }
    }
}
// The example displays the following output:
//    0.0000000000000000000000000001 (Decimal) --> 1E-28 (Double)
//    0.0000000000123456789123456789 (Decimal) --> 1.23456789123457E-11 (Double)
//    123 (Decimal) --> 123 (Double)
//    123.000000 (Decimal) --> 123 (Double)
//    123456789.123456789 (Decimal) --> 123456789.123457 (Double)
//    123456789123456789123456789 (Decimal) --> 1.23456789123457E+26 (Double)
//    -79228162514264337593543950335 (Decimal) --> -7.92281625142643E+28 (Double)
//    79228162514264337593543950335 (Decimal) --> 7.92281625142643E+28 (Double)

Açıklamalar

Çift duyarlıklı kayan nokta sayısının bir değerinden daha az anlamlı basamağı olduğundan bu işlem duyarlık kaybına Decimalneden olabilir.

Bu işleç, öğesinin Decimal öğesine açık olarak dönüştürülmesini Doubledestekler. Bu tür açık dönüştürmelerin sözdizimi dile bağlıdır ve ayrı dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir. Örnek, C#, C++ ve Visual Basic kullanarak bir Decimal değeri açıkça bir Double değere dönüştürdüğünüzde farklı dönüş değerlerini gösterir. Dilden bağımsız bir dönüştürme gerçekleştirmek için veya Convert.ToDouble(Decimal) yöntemini çağırabilirsinizDecimal.ToDouble(Decimal).

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to Char)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

bir öğesinin Decimal Unicode karakterine açık bir dönüştürmesini tanımlar.

C#
public static explicit operator char (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden bir Unicode karakteri.

Özel durumlar

value Char.MinValue değerinden küçük veya Char.MaxValue değerinden büyük.

Örnekler

Aşağıdaki örnek, açık ton Char dönüştürme işlecini kullanarak sayıları değerlere Char (Unicode karakterleri) dönüştürürDecimal.Decimal

C#
using System;

class Example
{
   public static void Main( )
   {
      // Define an array of decimal values.
      decimal[] values = { 3.33m, 55.5m, 77.7m, 123m, 123.999m, 170m,
                           188.88m, 222m, 244m, 8217m, 8250m, 65536m,
                           -1m };
      // Convert each value to a Char.
      foreach (decimal value in values) {
         try {
            char charValue = (char) value;
            Console.WriteLine("{0} --> {1} ({2:X4})", value,
                              charValue, (ushort) charValue);
         }
         catch (OverflowException) {
            Console.WriteLine("OverflowException: Cannot convert {0}",
                              value);
         }
      }
   }
}
// The example displays the following output:
//       3.33 --> ? (0003)
//       55.5 --> 7 (0037)
//       77.7 --> M (004D)
//       123 --> { (007B)
//       123.999 --> { (007B)
//       170 --> ª (00AA)
//       188.88 --> ¼ (00BC)
//       222 --> _ (00DE)
//       244 --> ô (00F4)
//       8217 --> ' (2019)
//       8250 --> > (203A)
//       OverflowException: Cannot convert 65536
//       OverflowException: Cannot convert -1

Açıklamalar

Bu işleç, öğesinin Decimal öğesine açık olarak dönüştürülmesini Chardestekler. Bu tür açık dönüştürmelerin söz dizimi dile bağlıdır ve tek tek dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir veya dönüştürmeyi hiç desteklemeyebilir. Örneğin, Visual Basic ve C++ derleyicileri bir dönüştürme için açık Decimal bir Char desteği yok.

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to Byte)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

öğesinin Decimal 8 bit işaretsiz tamsayıya açık dönüştürmesini tanımlar.

C#
public static explicit operator byte (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden 8 bit işaretsiz tamsayı.

Özel durumlar

value , Byte.MinValue değerinden küçük veya Byte.MaxValue değerinden büyük.

Örnekler

Aşağıdaki örnek, açık Decimal ton Byte dönüştürme işlecini kullanarak sayıları değerlere Byte dönüştürürDecimal.

C#
using System;

class Example
{
    public static void Main()
    {
        // Define an array of decimal values.
       decimal[] values = { 78m, new Decimal(78000, 0, 0, false, 3),
                            78.999m, 255.999m, 256m, 127.999m,
                            128m, -0.999m, -1m, -128.999m, -129m };
       foreach (var value in values) {
          try {
              Byte byteValue = (Byte) value;
              Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                                value.GetType().Name, byteValue,
                                byteValue.GetType().Name);
           }
           catch (OverflowException) {
              Console.WriteLine("OverflowException: Cannot convert {0}",
                                value);
           }
       }
    }
}
// The example displays the following output:
//       78 (Decimal) --> 78 (Byte)
//       78.000 (Decimal) --> 78 (Byte)
//       78.999 (Decimal) --> 78 (Byte)
//       255.999 (Decimal) --> 255 (Byte)
//       OverflowException: Cannot convert 256
//       127.999 (Decimal) --> 127 (Byte)
//       128 (Decimal) --> 128 (Byte)
//       -0.999 (Decimal) --> 0 (Byte)
//       OverflowException: Cannot convert -1
//       OverflowException: Cannot convert -128.999
//       OverflowException: Cannot convert -129

Açıklamalar

Bu işleç, öğesinin Decimal öğesine açık olarak dönüştürülmesini Bytedestekler. Bu tür açık dönüştürmelerin sözdizimi dile bağlıdır ve ayrı dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir. Örnek, C#, C++ ve Visual Basic kullanarak bir Decimal değeri açıkça bir Byte değere dönüştürdüğünüzde farklı dönüş değerlerini gösterir. Dilden bağımsız bir dönüştürme gerçekleştirmek için veya Convert.ToByte(Decimal) yöntemini çağırabilirsinizDecimal.ToByte(Decimal).

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Explicit(Decimal to Int64)

Kaynak:
Decimal.cs
Kaynak:
Decimal.cs
Kaynak:
Decimal.cs

öğesinin Decimal 64 bit işaretli tamsayıya açık dönüştürmesini tanımlar.

C#
public static explicit operator long (decimal value);

Parametreler

value
Decimal

Dönüştürülecek değer.

Döndürülenler

Dönüştürülen Decimalöğesini temsil eden 64 bit işaretli tamsayı.

Özel durumlar

value Int64.MinValue değerinden küçük veya Int64.MaxValue değerinden büyük.

Örnekler

Aşağıdaki örnek, açık Decimal ton Int64 dönüştürme işlecini kullanarak sayıları değerlere Int64 dönüştürürDecimal.

C#
// Example of the explicit conversions from decimal to long and
// decimal to ulong.
using System;

class DecimalToU_Int64Demo
{
    const string formatter = "{0,25}{1,22}{2,22}";

    // Get the exception type name; remove the namespace prefix.
    public static string GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring(
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Convert the decimal argument; catch exceptions that are thrown.
    public static void DecimalToU_Int64( decimal argument )
    {
        object Int64Value;
        object UInt64Value;

        // Convert the argument to a long value.
        try
        {
            Int64Value = (long)argument;
        }
        catch( Exception ex )
        {
            Int64Value = GetExceptionType( ex );
        }

        // Convert the argument to a ulong value.
        try
        {
            UInt64Value = (ulong)argument;
        }
        catch( Exception ex )
        {
            UInt64Value = GetExceptionType( ex );
        }

        Console.WriteLine( formatter, argument,
            Int64Value, UInt64Value );
    }

    public static void Main( )
    {
        Console.WriteLine(
            "This example of the explicit conversions from decimal " +
            "to long \nand decimal to ulong generates the following " +
            "output. It displays \nseveral converted decimal " +
            "values.\n" );
        Console.WriteLine( formatter, "decimal argument",
            "long/exception", "ulong/exception" );
        Console.WriteLine( formatter, "----------------",
            "--------------", "---------------" );

        // Convert decimal values and display the results.
        DecimalToU_Int64( 123M );
        DecimalToU_Int64( new decimal( 123000, 0, 0, false, 3 ) );
        DecimalToU_Int64( 123.999M );
        DecimalToU_Int64( 18446744073709551615.999M );
        DecimalToU_Int64( 18446744073709551616M );
        DecimalToU_Int64( 9223372036854775807.999M );
        DecimalToU_Int64( 9223372036854775808M );
        DecimalToU_Int64( - 0.999M );
        DecimalToU_Int64( - 1M );
        DecimalToU_Int64( - 9223372036854775808.999M );
        DecimalToU_Int64( - 9223372036854775809M );
    }
}

/*
This example of the explicit conversions from decimal to long
and decimal to ulong generates the following output. It displays
several converted decimal values.

         decimal argument        long/exception       ulong/exception
         ----------------        --------------       ---------------
                      123                   123                   123
                  123.000                   123                   123
                  123.999                   123                   123
 18446744073709551615.999     OverflowException  18446744073709551615
     18446744073709551616     OverflowException     OverflowException
  9223372036854775807.999   9223372036854775807   9223372036854775807
      9223372036854775808     OverflowException   9223372036854775808
                   -0.999                     0                     0
                       -1                    -1     OverflowException
 -9223372036854775808.999  -9223372036854775808     OverflowException
     -9223372036854775809     OverflowException     OverflowException
*/

Açıklamalar

Bu işleç, öğesinin Decimal öğesine açık olarak dönüştürülmesini Int64destekler. Bu tür açık dönüştürmelerin sözdizimi dile bağlıdır ve ayrı dil derleyicileri farklı uygulamalar sağlayabilir ve farklı sonuçlar döndürebilir. Örnek, C# ve Visual Basic kullanarak bir Decimal değeri bir değere Int64 açıkça dönüştürdüğünüzde farklı dönüş değerlerini gösterir. Dilden bağımsız bir dönüştürme gerçekleştirmek için veya Convert.ToInt64(Decimal) yöntemini çağırabilirsinizDecimal.ToInt64(Decimal).

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0