boll表达式
boll x= ture /flase
if(x)
{
//语句块Console.WriteLine ("");
}
1. 是帅哥就学好C#
bool
Handsome = true;
if (
Handsome)
{ Console.WriteLine ("是帅哥就学好C#");
}
单语句
if(x)如果为true 执行{}的东西
{
那么执行这里{ }
}
多语句
2. if(){ }else if(){ } 。。。。。else{ }
请从键盘输入考试分数 >90输入实在牛 >80输入要加油 >70好尴尬>60打酱油
Console.WriteLine ("请从键盘输入考试分数:");
int score = int.Parse (Console.ReadLine());
if (score > 90) {
Console.WriteLine ("学霸实在牛");
}
else if (score >80) {
Console.WriteLine ("学神要加油");
}
else if (score >70) {
Console.WriteLine ("学民好害羞");
}
else if (score >60) {
Console.WriteLine ("学弱打酱油");
}
else
{
Console.WriteLine ("学渣泪在流");
}
嵌套if
3. if(){if(){ } }
Console.WriteLine ("请输入True或者False");
string str = Console.ReadLine ();
if (str == "True")
{
Console.WriteLine ("是男人就学好C#");
}
if (str == "False")
{
Console.WriteLine ("好好学习");
}
4. if(){} else {}
如果张三的阶段测试成绩大于90分,老师奖励他一个苹果(吃的),否则惩罚默写笔记
Console.WriteLine ("请输入张三的成绩:");
牵扯数字之间的比较用int
int num = int.Parse (Console.ReadLine());
if (num>90)
{
Console.WriteLine ("考得不错,奖励你一个苹果");
}
else
{
Console.WriteLine ("罚你默写笔记!");
}