Tip on setting an empty string:

Tip on setting an empty string.  

C#:

Old approch:       string StranEmpty = "";  
Better approch   string StranEmpty = String.Empty;

VB.NET

Old approch:    Dim StranEmpty As String = ""
Better approch: Dim StranEmpty As String = String.Empty

Hope this helps :)

Published Friday, February 21, 2003 2:04 PM by SreedharK

Comments

# Why?

Friday, February 21, 2003 1:37 PM by Don Smith
I think it would be helpful if you'd explain why these approaches are better. Is something inherently better about a static method call versus providing a string literal? Are you suggesting this changes the behavior of string interning? Thanks.

# Tip on setting an empty string:

Sunday, February 23, 2003 12:00 PM by Deepak Sharma
From a performance point of view, Setting: (String.Length == 0) is twice as fast as using String.Empty.

If you've used FxCop one of the performance rules states that, Constructs such as "".Equals(someString) and String.Empty.Equals(someString) are less efficient than testing the string length. Replace these with checks for someString.Length == 0. Check it out here:

http://www.gotdotnet.com/team/libraries/FxCopRules/PerformanceRules.aspx

# re: Tip on setting an empty string:

Wednesday, November 19, 2003 12:20 AM by Sliver5
i suggest using Dim StranEmpty As String = "" is better and faster than using
Dim StranEmpty As String = String.Empty

# re: Tip on setting an empty string:

Wednesday, November 19, 2003 5:08 AM by Sreedhar
Silver5,

You did not read my next blog, have a glance at it, I already mentioned about it. Also it's a tip!

http://weblogs.asp.net/skoganti/posts/2860.aspx

Hope you will get it now!

# re: Tip on setting an empty string:

Thursday, February 09, 2012 12:36 AM by YzEreZApMp

xPvsYi Unbelievable. Class..!!

Leave a Comment

(required) 
(required) 
(optional)
(required)