《由浅入深学C#》
1. 显示:
bool b = Convert.ToBoolean(a); //使用系统Convert类
bool b = bool.Parse(a.ToString()); //类型本身的转换方法,强制转换
/***********************************
* 65 ==> A *
***********************************/
int a = 65;
char c = (char)a;
char c = Convert.ToChar(a);
/***********************************
* A ==> 65 *
***********************************/
int a = (int)c;
int a = Convert.ToInt32(c);
is 运算符通常用来检验类型之间的兼容性;
Object obj = true;
Console.WriteLine(obj is bool); //输出 ture 或者false
as运算符用于执行可兼容类型之间的转换,只执行引用转换和装箱转换,无法执行其他转换。
Object obj = "hello";
string str = obj as string;
如果兼容str是hello否则返回null;
随机数:
Random ran = new Random();
ran.Next(100,999); //100,999分别是随机数的上下界。但只能取到下界,不能取到上界。是整数。
@用来取消转义字符
路径
@"C:\temp"
"C:\\temp"
两者相等。