Export (0) Print
Expand All

Convert.ToChar Method (Int64)

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

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static char ToChar (
	long value
)
public static char ToChar (
	long value
)
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.

Exception typeCondition

OverflowException

value is less than Char.MinValue or greater than Char.MaxValue.

The following code sample attempts to convert an Int64 to Char, throwing OverflowException on failure.

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);
}

public void ConvertLongChar(long longVal)
{
    char charVal = 'a';

    try {        
        charVal = System.Convert.ToChar(longVal);
        System.Console.WriteLine("{0} as a char is {1}", 
            System.Convert.ToString(longVal), 
            System.Convert.ToString(charVal));
    }
    catch (System.OverflowException exp) {        
        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}", 
        System.Convert.ToString(charVal), 
        System.Convert.ToString(longVal));
} //ConvertLongChar

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft