Difference between String.Empty and "" in Asp.Net?

Just a few days back 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.

1 comments:

Interview questions answers pdf said...

http://allinterviewquestionsandanswerspdf.blogspot.in/2016/06/top-27-aspnet-interview-questions-and.html

Post a Comment