分支是控制下一步執(zhí)行哪行代碼的過程。三元運算符;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( " 沒有找到對應(yīng)數(shù)據(jù) " ); break ; } Console.ReadKey(); } }
?
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
