-4
我試圖找到一種更簡單的方法將此三元表達式轉換爲if else表達式。如何將這個三元表達式轉換爲if語句?
Account account = selection != 1 ? (Account)customer.Saving : (Account)customer.Checking;
我試圖找到一種更簡單的方法將此三元表達式轉換爲if else表達式。如何將這個三元表達式轉換爲if語句?
Account account = selection != 1 ? (Account)customer.Saving : (Account)customer.Checking;
你可以寫:
Account account;
if(selection != 1)
{
account= (Account)customer.Saving
}
else{
account= (Account)customer.Checking;
}
爲什麼downvote?我不認爲我寫了任何錯誤。請解釋誰曾經低調投票 – kritikaTalwar
'客戶賬戶;如果(選擇!= 1){account =(account)customer.Saving} else {account =(Account)customer.Checking; }'......但是爲什麼? – Lanorkin
你確定你是編碼的人嗎? –
謝謝你,非常感謝 – user3238526