|
Cet article a fait l'objet d'une traduction automatique. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. Informations supplémentaires.
|
Traduction
Source
|
Decimal Explicit, conversion (Decimal to Int64)
Espace de noms : System
Assembly : mscorlib (dans mscorlib.dll)
Paramètres
- value
- Type : System.Decimal
Valeur à convertir.
| Exception | Condition |
|---|---|
| OverflowException |
// 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 */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (rôle principal du serveur non pris en charge), Windows Server 2008 R2 (rôle principal du serveur pris en charge avec SP1 ou version ultérieure ; Itanium non pris en charge)
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.