标签:
checked:
byte b = 255;
checked
{
b++;
}
Console.WriteLine(b.ToString());
执行出错:算术运算导致溢出。
unchecked:
byte b = 255;
unchecked
{
b++;
}
Console.WriteLine(b.ToString());
执行不出错:不检查是否溢出
is运算符
is运算符可以检查对象是否与特定的类型兼容
int i=10;
if(i is object)
{
Console.WriteLine(true);
}
as运算符
as运算符用于执行引用类型的显式类型转换
object o1= "some string"`
object o2 = 5;
string s1 = o1 as string; // s1 = "sq1e string"
string s2 = o2 as string; // s2 = null
可空类型和运算符
int? a = null;
int? b = -5;
if (a >= b)
{
Console.WriteLine("a>=b");
}
else
{
Console.WriteLine("a<b");
}
标签:
原文地址:http://www.cnblogs.com/hank-chen/p/4599167.html