首页 / 软件开发 / C# / C#语法练习(4): 类型转换
C#语法练习(4): 类型转换2011-09-22 博客园 万一使用 Convert 类:ToBoolean -> bool
ToByte -> byte
ToChar -> char
ToDateTime -> DateTime
ToDecimal -> decimal
ToDouble -> double
ToInt16 -> short
ToInt32 -> int
ToInt64 -> long
ToSByte -> sbyte
ToSingle -> float
ToString -> string
ToUInt16 -> ushort
ToUInt32 -> uint
ToUInt64 -> ulong
using System;
class MyClass
{
static void Main()
{
int num;
string str;
num = 99;
str = Convert.ToString(num);
Console.WriteLine(str);
str = "123";
num = Convert.ToInt32(str);
Console.WriteLine(num);
Console.ReadKey();
}
}