string.IsNullOrEmpty() vs string.NotNullOrEmpty()

前端 未结 14 1078
遇见更好的自我
遇见更好的自我 2021-02-01 02:56

I\'m curious if any developers use string.IsNullOrEmpty() more often with a negative than with a positive

e.g.

if (!string.IsNullOrEmpty())
14条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-01 03:43

    I had the same question before I realized all I had to do to flip the question was to put the Not operator in front of the conditional. I think it cleande up my code some.

     // need to check if tBx_PTNum.Text is empty
            /*
            if (string.IsNullOrWhiteSpace(tBx_PTNum.Text))
            {
                // no pt number yet
            }
            else
            {
                ptNum = Convert.ToInt32(tBx_PTNum.Text);
            }
            */
            
            if(!string.IsNullOrEmpty(tBx_PTNum.Text))
            {
                ptNum = Convert.ToInt32(tBx_PTNum.Text);
            }
    

提交回复
热议问题