C#入门--分支语句
3种分支技术:
- 三元运算符
- if语句
- switch语句
<test>?<resultIfTrue>:<resultIfFalse>
IF语句
if (<test>)
<code executed if <test> is true >;
或者
if (<test>)
<code executed if <test> is true >;
else
<code executed if <test> is false >;
switch 语句
switch (<testVar>)
{
case<comparisonVal1>:
<code to execute if <testVar>==<comparisonVal1>>;
break;
case<comparisonVal2>:
<code to execute if <testVar>==<comparisonVal1>>;
break;
...
default:
<code to execute if <testVar>!=<comparisonVals>>;
break;
}