C#_if else语句

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if else 语法
if(<test>)
<code executed if <test> is true>//满足条件执行段段
else
<code executed if <test> is false>//不满足条件执行这段

如果if和else要执行的代码有多行,要加上{}组成一个块
if(<test>)
{
<code1 executed if <test> is true>
<code2 executed if <test> is true>
}
else
{
<code1 executed if <test> is false>
<code2 executed if <test> is false>
}

##实例

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
int num1 = Convert.ToInt32(str);
if (num1 > 50)
{
num1++;
Console.WriteLine("大于50");
}
else
{
num1--;
Console.WriteLine("小于50");
}

Console.ReadKey();

}
}
}