基本: . () [] x++ x-- new typeof checked unchecked -> ::
一元: + - ! ~ ++x --x (T)x True False & sizeof
乘除: * / %
加減: + -
移位: << >>
關系: < > <= >= is as
相等: == !=
邏輯: & ^ |
條件: && ||
賦值: = += -= *= /= %= &= |= ^= <<= >>=
選擇: ?: ??
其他: =>
整數 / 整數 = 整數
using System;
class MyClass
{
static void Main()
{
double d;
d = 14 / 4;
Console.WriteLine(d); //3
d = 14 / 4.0;
Console.WriteLine(d); //3.5
d = 14.0 / 4.0;
Console.WriteLine(d); //3.5
d = 14.0 / 4;
Console.WriteLine(d); //3.5
Console.WriteLine();
float f;
f = 14 / 4;
Console.WriteLine(f); //3
f = (float)(14.0 / 4.0); /* 默認返回 double, 因而需要轉換 */
Console.WriteLine(f); //3.5
Console.WriteLine();
int i;
i = 14 / 4;
Console.WriteLine(i); //3
i = (int)(14.0 / 4.0);
Console.WriteLine(i); //3
i = 14 % 4;
Console.WriteLine(i); //2
Console.ReadKey();
}
}