.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

String.Empty Vs Empty Quotes Vs String.length

Posted By:shahin       Posted Date: February 26, 2009    Points: 25    Category: C#    URL: http://www.dotnetspark.com  
 

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

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.

Ref. String.Empty Vs Empty Quotes Vs String.length

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend