Difference between !String.IsNullOrEmpty and !='' and !=null in C#

Last Reply 3 months ago By pandeyism

Posted 3 months ago

Can anyone tell me what does this if stmts mean? i am new to C#.

1.
if (!string.IsNullOrEmpty(textbox.Text)) {
.........
}

2.
 if (Textbox.Text != "")
 {
 ....
 }
 
 3.
 
 if (Textbox.Text != null)
 {
 ....
 }
You are viewing reply posted by: pandeyism 3 months ago.
Posted 3 months ago Modified on 3 months ago

Hi Abhays,

Abhays says:
if (!string.IsNullOrEmpty(textbox.Text)) {
.........
}

 It is used to check whether the specified string is not null or an Empty string.  If string is null or an Empty then this statement will not execute.

Abhays says:
 if (Textbox.Text != "")
 {
 ....
 }

  It is used to check whether the specified string is not an Empty string. If string is an Empty then this statement will not execute.

Abhays says:
if (Textbox.Text != null)
 {
 ....
 }

   It is used to check whether the specified string is not null string. If string is null then this statement will not execute.