One liner for If string is not null or empty else

后端 未结 6 1507
孤城傲影
孤城傲影 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:48

    Old question, but thought I'd add this to help out,

    #if DOTNET35
    bool isTrulyEmpty = String.IsNullOrEmpty(s) || s.Trim().Length == 0;
    #else
    bool isTrulyEmpty = String.IsNullOrWhiteSpace(s) ;
    #endif
    

提交回复
热议问题