C#_使用if else语句进行多条件判断

1
2
3
4
5
6
7
8
if(){    
}else if(){
}else if(){
}else{
}

else if可以有0或者多个
else 只能有0或者1个

实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _23
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("您考了多少分?");
string str = Console.ReadLine();
int score = Convert.ToInt32(str);
if (score>=90)
{
Console.WriteLine("优秀");
}
else if (score >= 80 && score < 90)
{
Console.WriteLine("良");
}
else if (score>=60&&score<80)
{
Console.WriteLine("中");
}
else
{
Console.WriteLine("差,继续努力喔!");
}
Console.ReadKey();
}
}
}