Export (0) Print
Expand All

Convert.ToDecimal Method (Char)

.NET Framework 1.1

Calling this method always throws InvalidCastException.

[Visual Basic]
Overloads Public Shared Function ToDecimal( _
   ByVal value As Char _
) As Decimal
[C#]
public static decimal ToDecimal(
 char value
);
[C++]
public: static Decimal ToDecimal(
 __wchar_t value
);
[JScript]
public static function ToDecimal(
   value : Char
) : Decimal;

Parameters

value
A Unicode character.

Return Value

This conversion is not supported. No value is returned.

Exceptions

Exception Type Condition
InvalidCastException This conversion is not supported.

Remarks

This method is reserved for future use.

Example

[Visual Basic, C#, C++] The following code sample attempts to convert a Char value to Decimal, throwing InvalidCastException upon failure.

[Visual Basic] 
Public Sub ConvertCharDecimal(ByVal charVal As Char)
    Dim decimalVal As [Decimal] = 0

    ' Char to decimal conversion is not supported and will always
    ' throw an InvalidCastException.
    Try
        decimalVal = System.Convert.ToDecimal(charVal)
    Catch exception As System.InvalidCastException
        System.Console.WriteLine( _
             "Char-to-decimal conversion is not supported " + _
             "by the framework.")
    End Try

    'Decimal to char conversion is also not supported.
    Try
        charVal = System.Convert.ToChar(decimalVal)
    Catch exception As System.InvalidCastException
        System.Console.WriteLine( _
            "Decimal-to-char conversion is not supported " + _
            "by the framework.")
    End Try
End Sub

[C#] 
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.");
    }
}

[C++] 

   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(S"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(S"Decimal-to-char conversion is not supported by the framework.");
      }
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Convert Class | Convert Members | System Namespace | Convert.ToDecimal Overload List | Char

Show:
© 2014 Microsoft