System.Convert.ToChar 方法 (Int32)

方法描述

将指定的 32 位带符号整数的值转换为其等效的 Unicode 字符。

语法定义(C# System.Convert.ToChar 方法 (Int32) 的用法)

public static char ToChar(
	int value
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
value System-Int32 要转换的 32 位带符号整数。
返回值 System.Char 一个等于 value 的 Unicode 字符。

提示和注释

System.Convert.ToChar 方法 (Int32)例子

下面的示例将一个数组的带符号整数转换为 Char 值。

int[] numbers = { -1, 0, 40, 160, 255, 1028, 
                     2011, 30001, 207154, Int32.MaxValue };
   char result;
   foreach (int number in numbers)
   {
      try {
         result = Convert.ToChar(number);
         Console.WriteLine("{0} converts to '{1}'.", number, result);
      }   
      catch (OverflowException) {
         Console.WriteLine("{0} is outside the range of the Char data type.",
                           number);
      }
   }   
}
//       -1 is outside the range of the Char data type.
//       0 converts to ' '.
//       40 converts to '('.
//       160 converts to ' '.
//       255 converts to 'ÿ'.
//       1028 converts to '?'.
//       2011 converts to '?'.
//       30001 converts to '?'.
//       207154 is outside the range of the Char data type.
//       2147483647 is outside the range of the Char data type.

异常

异常 异常描述
OverflowException value 小于 Char.MinValue 或大于 Char.MaxValue。

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1 受以下版本支持:

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。