---------------------- Windows Phone 7手机开发、Net培训、期待与您交流! ----------------------
一、运算符
1、算数操作符
种类:
+加法操作符
-减法操作符
*乘法操作符
/除法操作符
%求余操作符
++自加1
--自减1
用法:
取某个范围之内的数 10%3=1(10以内的)
取个位数37=7
取十位数78/10=7
倍数倍数%7=0(7的倍数)
int chinese = 80;
int math = 80;
int english = 80;
int sum = chinese + math + english;
int avg = sum / 3;
Console.WriteLine("你的总成绩是{0},你的平均成绩是{1}", sum, avg);
int tx = 35;
int trouseres = 120;
int sum = 3 * tx + 2 * trouseres;
double dz = sum * 0.88;
Console.WriteLine("小明应付的总额是{0},小明打折后的总额{1}", sum, dz);
2、关系操作符
种类:
==等于
!=不等于
<小于
>大于
<=小于等于
>=大于等于
int i = 0;
while (i < 5)
{
Console.WriteLine("钱财乃是身外之物");
i++;
}
int i = 0;
while (i < 100)
{
Console.WriteLine("欢迎光临");
i++;
}
Console.WriteLine("请输入李四的年终评级(A-E)");
string input =Console.ReadLine();
decimal salary = 5000m;
bool lay = false;
if (input =="A")
{
salary += 500;
}
else if (input == "B")
{
salary += 200;
}
else if (input == "C")
{
salary += 0;
}
else if (input == "D")
{
salary -= 200;
}
else if (input == "E")
{
salary -= 500;
}
else
{
Console.WriteLine("您输入的信息有误,请输入大写的ABCDE");
lay =true;
}
if (lay == false)
{
Console.WriteLine("李四的工资是5000");
}
3、逻辑操作符
种类:
&&逻辑与
||逻辑或
!逻辑非
Console.WriteLine("ok?(y/n)");
string answer =Console.ReadLine();
int i = 0;
while (answer =="n" && i < 10)
{
Console.WriteLine("a");
i++;
Console.WriteLine("b");
answer =Console.ReadLine();
}
Console.WriteLine("b");
4、三元运算符
形式:
表达式?值1:值2;
若表达式为true返回值1,否则返回值2
例子
//判断成年与否
Console.WriteLine("请输入你的年龄:");
int age = Convert.ToInt32(Console .ReadLine ());
string panduan = age > 18 ? "成年" : "未成年";
Console.WriteLine(panduan);
5、赋值操作符
类型:
=赋值
+= a+=1相当于a=a+1
-=
*=
/=
%=
int year = 2006;
double student = 80000;
while(student<200000)
{
student = student * 1.25;/
year++;
}
Console.WriteLine(year);
----------------------Windows Phone 7手机开发、Net培训、期待与您交流! ----------------------
详细请查看:http://net.itheima.com/