search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

C# if 簡寫 [ ?: 運算子 ] – jashliao部落格

C# if 簡寫 [ ?: 運算子 ]

資料來源:https://docs.microsoft.com/zh-tw/dotnet/csharp/language-reference/operators/conditional-operator

int input = Convert.ToInt32(Console.ReadLine());  
string classify;  

// if-else construction.  
if (input > 0)  
    classify = “positive”;  
else  
    classify = “negative”;  

// ?: conditional operator.  
classify = (input > 0) ? “positive” : “negative”;  

 

 

 

 



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦