Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はこのコードを手に入れたと思います、
string a, b; b = null;
「?」の使い方は?b が null または空でないかどうかをチェックする演算子。
「a」でnullまたは空でない場合、「b」の値を取得したい
使いたくない、string.IsNullOrEmpty()、理由 ---> 「if and else」は使いたくない :)
次の質問を推測させてください。 if と else を使用したくないのはなぜですか。
これはうまくいきます:
a = (b ?? "") == "" ? a : b;
しかし、一体なぜこれを使用しないのでしょうか:
a = string.IsNullOrEmpty(b) ? a : b;
これに頼る必要はありませifんelse...
if
else
それはあなたが探しているものですか : a = (b == null || b.Length < 1 ? a : b);?
a = (b == null || b.Length < 1 ? a : b);