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

Last Reply one month ago By pandeyism

Posted one month 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 one month ago.
Posted one month ago Modified on one month 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.