表达式

字面量

整数字面量

C#图解教程读书笔记(第8章 表达式和运算符)

字符字面量

C#图解教程读书笔记(第8章 表达式和运算符)

字符串字面量

求值顺序

优先级

C#图解教程读书笔记(第8章 表达式和运算符)

结合性

C#图解教程读书笔记(第8章 表达式和运算符)

与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的话,则需要显式强制转换。

 

运算符重载

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

 

相关文章:

  • 2021-08-26
  • 2021-10-05
  • 2022-01-11
  • 2021-07-13
  • 2021-12-30
  • 2021-09-24
  • 2022-03-11
猜你喜欢
  • 2021-05-30
  • 2021-06-13
  • 2021-09-30
  • 2022-01-25
  • 2022-01-23
相关资源
相似解决方案