2017-04-18 137 views
-4

我試圖找到一種更簡單的方法將此三元表達式轉換爲if else表達式。如何將這個三元表達式轉換爲if語句?

Account account = selection != 1 ? (Account)customer.Saving : (Account)customer.Checking; 
+3

'客戶賬戶;如果(選擇!= 1){account =(account)customer.Saving} else {account =(Account)customer.Checking; }'......但是爲什麼? – Lanorkin

+0

你確定你是編碼的人嗎? –

+0

謝謝你,非常感謝 – user3238526

回答

-1

你可以寫:

Account account; 
if(selection != 1) 
{ 
    account= (Account)customer.Saving 
} 
else{ 
    account= (Account)customer.Checking; 
} 
+0

爲什麼downvote?我不認爲我寫了任何錯誤。請解釋誰曾經低調投票 – kritikaTalwar

相關問題