分支是控制下一步执行哪行代码的过程。三元运算符;if语句;switch语句
三元运算符:
<test> ? <resultiftrue> : <resultiffalse>
class
Program
{
static
void
Main(
string
[] args)
{
int
myInt =
50
;
string
re=(myInt <
10
) ?
"
条件成立
"
:
"
条件不成立
"
;
Console.WriteLine(
"
{0}
"
, re);
Console.ReadKey();
}
}
if语句重写上述案例:
class
Program
{
static
void
Main(
string
[] args)
{
int
myInt =
50
;
if
(myInt <
10
)
{
Console.WriteLine(
"
条件成立
"
);
}
else
{
Console.WriteLine(
"
条件不成立
"
);
}
Console.ReadKey();
}
}
switch案例:
class
Program
{
static
void
Main(
string
[] args)
{
int
x =
55
;
switch
(x) {
case
7
:
Console.WriteLine(
"
7
"
);
break
;
case
8
:
Console.WriteLine(
"
8
"
);
break
;
default
:
Console.WriteLine(
"
没有找到对应数据
"
);
break
;
}
Console.ReadKey();
}
}

