第九节 运算符和表达式(二)
一。自增运算符和自减运算符。++,--
后置:先使用,后自身自增。
前置:先自身自增,后使用。
自增,自减,1.用于变量。2.不能用作表达式。
class Program { static void Main(string[] args) { int day = 12; int today; today = day++; Console.WriteLine("today={0}day={1}",today,day); } }
二.赋值运算符.=,+=,-=,*=,/=,%=;
三,优先级
练习下 当a=2;b=3时如下程序a,b结果
class Program { static void Main(string[] args) { int a = 2, b = 3; a = a * ++b + b; Console.WriteLine("{0}{1}",a,b); } }