This documentation is archived and is not being maintained.

Convert.ToChar Method (Int64)

.NET Framework 1.1

Converts the value of the specified 64-bit signed integer to its equivalent Unicode character.

[Visual Basic]
Overloads Public Shared Function ToChar( _
   ByVal value As Long _
) As Char
[C#]
public static char ToChar(
 long value
);
[C++]
public: static __wchar_t ToChar(
 __int64 value
);
[JScript]
public static function ToChar(
   value : long
) : Char;

Parameters

value
A 64-bit signed integer.

Return Value

The Unicode character equivalent to the value of value.

Exceptions

Exception Type Condition
OverflowException value is less than Char.MinValue or greater than Char.MaxValue.

Example

[Visual Basic, C#, C++] The following code sample attempts to convert an Int64 to Char, throwing OverflowException on failure.

[Visual Basic] 
Public Sub ConvertLongChar(ByVal longVal As Long)

    Dim charVal As Char = "a"c

    Try
        charVal = System.Convert.ToChar(longVal)
        System.Console.WriteLine("{0} as a char is {1}", _
                                  longVal, charVal)
    Catch exception As System.OverflowException
        System.Console.WriteLine( _
            "Overflow in Long-to-Char conversion.")
    End Try

    ' A conversion from Char to Long cannot overflow.
    longVal = System.Convert.ToInt64(charVal)
    System.Console.WriteLine("{0} as a Long is {1}", _
                              charVal, longVal)
End Sub

[C#] 
public void ConvertLongChar(long longVal) {

    char    charVal = 'a';

    try {
        charVal = System.Convert.ToChar(longVal);
        System.Console.WriteLine("{0} as a char is {1}",
            longVal, charVal);
    } 
    catch (System.OverflowException) {
        System.Console.WriteLine(
            "Overflow in long-to-char conversion.");
    }
    
    // A conversion from Char to long cannot overflow.
    longVal = System.Convert.ToInt64(charVal);
    System.Console.WriteLine("{0} as an Int64 is {1}",
        charVal, longVal);
}

[C++] 

   void ConvertLongChar(Int64 longVal)
   {
      Char    charVal = 'a';

      try {
         charVal = System::Convert::ToChar(longVal);
         System::Console::WriteLine(S" {0} as a char is {1}",
            __box(longVal), __box(charVal));
      } catch (System::OverflowException*) {
         System::Console::WriteLine(S"Overflow in long-to-char conversion.");
      }

      // A conversion from Char to long cannot overflow.
      longVal = System::Convert::ToInt64(charVal);
      System::Console::WriteLine(S" {0} as an Int64 is {1}",
         __box(charVal), __box(longVal));
   }

[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, Common Language Infrastructure (CLI) Standard

See Also

Convert Class | Convert Members | System Namespace | Convert.ToChar Overload List

Show: