Difference between String.Empty, Empty Quotes and String.length
Posted on 6/21/2007 6:29:25 PM
in #Dot Net Framework
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
|
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
|