One liner for If string is not null or empty else

后端 未结 6 1472
孤城傲影
孤城傲影 2020-12-08 18:03

I usually use something like this for various reasons throughout an application:

if (String.IsNullOrEmpty(strFoo))
{
     FooTextBox.Text = \"0\";
}
else
{
          


        
6条回答
  •  时光说笑
    2020-12-08 18:55

    You could use the ternary operator:

    return string.IsNullOrEmpty(strTestString) ? "0" : strTestString
    
    FooTextBox.Text = string.IsNullOrEmpty(strFoo) ? "0" : strFoo;
    

提交回复
热议问题