表达式

字面量

整数字面量

字符字面量

字符串字面量

求值顺序

优先级

结合性

与C和C++不同,在C#中的数字不具有布尔意义。

各种运算符的作用(过)

用户定义类型转换

class XiXiInt

{

const int iMaxValue = 100;

const int iMinValue = 0;

private int theValue = 0;

public int TheValue

{

get { return theValue; }

set

{

if (value < iMinValue)

{

theValue = iMinValue;

}

else

{

theValue = value > iMaxValue ? iMaxValue : value;

}

}

}

public static implicit operator int(XiXiInt iXiXi)

{

return iXiXi.TheValue;

}

public static implicit operator XiXiInt(int x)

{

XiXiInt iXiXi = new XiXiInt();

iXiXi.TheValue = x;

return iXiXi;

}

}

显式转换和强制转换运算符

如果将implicit改为explicit的话,则需要显式强制转换。

 

运算符重载

运算符重载只能用于类和结构。

 

posted on 2014-04-14 12:13  偶是一只IT小小鸟  阅读(233)  评论(0编辑  收藏  举报