We usually use the code below to check if a string is empty.
if(s=="")
Use the code below for 3 times quicker way.
if(s.Length==0)
If the string "s" may has some spaces s=" ", you can use this code:
if(s.Trim().Length==0)
And if you also want to check the strinf if it is NULL, use:
if(String.IsNullOrEmpty(s.Trim()))

Kadir CamogluPosted Feb 2, 2007, 2:34 AM
if(s.Length=0) just a writing mistake. And I immediately corrected it. And IsNullOrEmpty checking NULL values too. Thanks to both of you.
Anh Duc ThaiPosted Feb 1, 2007, 8:34 PM
That way is also checking for NULL value.
ADEBISI FolusoPosted Feb 1, 2007, 8:22 AM
What if the string contains the space character ' '? Though not empty, it makes no sense (not in password field, anyway). Code like this will do: ... string s = " "; if (s.Trim().Length == 0) ... Less I forget, your above code has some mistakes, you wrote if (s.Length = 0) instead of if (s.Length == 0) Happy Coding!