C#中的类型转换
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Demo { class Program { static void Main(string[] args) { int val = 97 ; Console.WriteLine( "{0}" ,val); // 97 bool boolVal = Convert.ToBoolean(val); Console.WriteLine( "{0}" , boolVal); // true byte byteVal = Convert.ToByte(val); Console.WriteLine( "{0}" , byteVal); // 97 char charVal = Convert.ToChar(val); Console.WriteLine( "{0}" ,charVal); // a decimal decimalVal = Convert.ToDecimal(val); Console.WriteLine( "{0}" , decimalVal); // 97 double doubleVal = Convert.ToDouble(val); Console.WriteLine( "{0}" , doubleVal); // 97 short shortVal = Convert.ToInt16(val); Console.WriteLine( "{0}" , shortVal); // 97 int intVal = Convert.ToInt32(val); Console.WriteLine( "{0}" , intVal); // 97 long longVal = Convert.ToInt64(val); Console.WriteLine( "{0}" , longVal); // 97 sbyte sbyteVal = Convert.ToSByte(val); Console.WriteLine( "{0}" , sbyteVal); // 97 float floatVal = Convert.ToSingle(val); Console.WriteLine( "{0}" , floatVal); // 97 string stringVal = Convert.ToString(val); Console.WriteLine( "{0}" , stringVal); // 97 ushort ushortVal = Convert.ToUInt16(val); Console.WriteLine( "{0}" , ushortVal); // 97 uint uintVal = Convert.ToUInt32(val); Console.WriteLine( "{0}" , uintVal); // 97 ulong ulongVal = Convert.ToUInt64(val); Console.WriteLine( "{0}" , ulongVal); // 97 Console.ReadKey(); } } } 本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6728339.html,如需转载请自行联系原作者