Zi 字媒體
2017-07-25T20:27:27+00:00
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”;
寫了
5860316篇文章,獲得
23313次喜歡