Convert.ToChar (Método) (Decimal)
.NET Framework 3.5
Actualización: noviembre 2007
Cuando se llama a este método, siempre se produce InvalidCastException.
Ensamblado: mscorlib (en mscorlib.dll)
public static char ToChar( Decimal value )
public static function ToChar( value : decimal ) : char
Parámetros
- value
- Tipo: System.Decimal
Número Decimal.
| Excepción | Condición |
|---|---|
| InvalidCastException | No se admite esta conversión. |
En el siguiente ejemplo de código, se intenta convertir un Decimal en un Char, y se produce una excepción InvalidCastException si se produce un error.
public void ConvertCharDecimal(char charVal) { Decimal decimalVal = 0; // Char to decimal conversion is not supported and will always // throw an InvalidCastException. try { decimalVal = System.Convert.ToDecimal(charVal); } catch (System.InvalidCastException) { System.Console.WriteLine( "Char-to-decimal conversion is not supported " + "by the framework."); } //Decimal to char conversion is also not supported. try { charVal = System.Convert.ToChar(decimalVal); } catch (System.InvalidCastException) { System.Console.WriteLine( "Decimal-to-char conversion is not supported " + "by the framework."); } }
public void ConvertCharDecimal(char charVal)
{
Decimal decimalVal = System.Convert.ToDecimal(0);
// Char to decimal conversion is not supported and will always
// throw an InvalidCastException.
try {
decimalVal = System.Convert.ToDecimal(charVal);
}
catch (System.InvalidCastException exp) {
System.Console.WriteLine(
("Char-to-decimal conversion is not supported "
+ "by the framework."));
}
//Decimal to char conversion is also not supported.
try {
charVal = System.Convert.ToChar(decimalVal);
}
catch (System.InvalidCastException exp) {
System.Console.WriteLine(
("Decimal-to-char conversion is not supported "
+ "by the framework."));
}
} //ConvertCharDecimal
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile para Smartphone, Windows Mobile para Pocket PC, Xbox 360
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.