簡體   English   中英

如何編寫具有多個條件的簡寫if語句

[英]How to write shorthand if-statement with multiple conditions

例如我想寫:

txt1.Text=="A" || txt2.Text="A" ? return true : return false

我知道如何在一種情況下工作,但在兩種情況下我不知道。

txt2.Text =“ A”代替txt2.Text =“ =” A“,這不是我的意思。

我的問題是,如何為該特定條件添加條件。 是的,我知道如何使用。

在其他情況下使用的常規方法是:

txt1.Text ==“ A”? 返回true:返回false

我想改善這一點。

我編寫的代碼無法正常工作。

謝謝

你在找嗎

return txt1.Text == "A" || txt2.Text == "A";

我認為這就是您想要的。

if(txt1.Text == "A" || txt2.Text == "A") //checks if txt1 is A OR txt2 is A
{
return true;
}
else
{
return false;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM