C#ハテナコロン

たまに見かけて「なんだったっけこれ?」って毎回ググってるので・・・

?: 演算子(三項条件演算子)

https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/operators/conditional-operator

 

式1 ハテナ 式2 コロン 式3;

 

bool式の評価結果 (true または false) に応じて、2 つの式のいずれかの結果を返す

 


condition ? consequent : alternative

condition=trueならconsequent
condition=falseならalternativeになる

 

if文で書くなら

 

if(condition ){

consequent

}else{

alternative

}

 

これと同じ。

 

長くなるのを短くするために使うことが多いハズ

a = b ? c : e ;

関連記事


Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 44

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 45

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 46

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 44

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 45

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 46

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 44

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 45

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 46

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 44

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 45

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 46

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 44

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 45

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 46

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 44

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 45

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 46

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 44

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 45

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 46

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 44

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 45

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 46

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 44

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 45

Warning: Trying to access array offset on false in /home/sirohood/sirohood.exp.jp/public_html/wp-content/themes/oria/single.php on line 46



コメントを残す

※コメントは承認後に表示されます。
 コメントを公開されたくない場合、名前の後に「:非公開」とつけてください。