Difference between String.Empty, Empty Quotes and String.length

Hi

A few days back when I was working with string. At many point of time I had to make a checking for empty string. I started thinking about the difference between “” and string.empty. and which one is a better way to check if the string is empty or not.

The difference between string.Empty and “” is very small. String.empty will not create any object while “” will create a new object in the memory for the checking. Hence string.empty is better in memory management.

But the comparison with string.length == 0 will be even faster and the better way to check for the empty string. And I also have a bias for checking with string.length in this case. But do not forget to make a checking for null value if you are also expecting null value in the comparison.

Happy coding
Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Posted on 6/21/2007 7:50:34 PM

Have you tried string.IsNullOrEmpty()?

Posted on 6/22/2007 12:36:53 AM

Smart, you mention check for null,

then you could use string.IsNullOrEmpty checking null and empty

Posted on 8/26/2007 10:56:16 PM

Excellent vikram.........Keep it up

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2008 Vikram Lakhotia