473,323 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Why string.Empty is better then ""

hi
can u write me
Why string.Empty is better then ""

bye

Nov 17 '05 #1
8 13570
"monu" <gt*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
hi
can u write me
Why string.Empty is better then ""


It is often argued that it more clearly exresses the intent of the coder. I
would usually agree with this.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
Nov 17 '05 #2
This has been brought up before. Most MS code uses String.Empty but from
what has been stated before it's real purpose is to simply provide languages
that don't directly support strings the ability to represent an empty string
anyway. For languages that do support strings (such as C#) then the "" is
fine. I would, in general, disagree that String.Empty is more clear than ""
because "" is far more concise and universally known as an empty string. The
only exception would be when it could be construed as a string with a single
space. This can sometimes be hard to discern depending on font size.
Performance wise however they are equivalent.

Michael Taylor - 9/19/05

"monu" wrote:
hi
can u write me
Why string.Empty is better then ""

bye

Nov 17 '05 #3
Tim Haughton wrote:
can u write me
Why string.Empty is better then ""


It is often argued that it more clearly exresses the intent of the coder. I
would usually agree with this.


Right, and it's theoretically more flexible/portable, because you don't
rely on the fact that "" is the empty string. Hard to come up with a
practical example here, but the String.Empty syntax simply introduces that
additional layer of abstraction. Personally, I like the fact that it's
there and I use it, although it doesn't really make any difference to the
workings of your code (yet?).
Oliver Sturm
--
Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)
Nov 17 '05 #4
"Oliver Sturm" <ol****@sturmnet.org> wrote in message
news:xn****************@msnews.microsoft.com...
Tim Haughton wrote:
can u write me
Why string.Empty is better then ""


It is often argued that it more clearly exresses the intent of the coder. Iwould usually agree with this.


Right, and it's theoretically more flexible/portable, because you don't
rely on the fact that "" is the empty string. Hard to come up with a
practical example here, but the String.Empty syntax simply introduces that
additional layer of abstraction. Personally, I like the fact that it's
there and I use it, although it doesn't really make any difference to the
workings of your code (yet?).


You're right on the portability front, just like I use Environment.NewLine
instead of "\r\n".

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton

Nov 17 '05 #5
Oliver Sturm wrote:
Tim Haughton wrote:
can u write me
Why string.Empty is better then ""

<snip>

Also see:
http://blogs.msdn.com/brada/archive/.../22/49997.aspx

Looking at the IL generated, there's a difference, but both strings will
be pulled out of the string interning cache so there will be no
difference at runtime.

--
Lasse Vågsæther Karlsen
http://www.vkarlsen.no/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Nov 17 '05 #6
Tim Haughton <ti*********@gmail.com> wrote:
You're right on the portability front, just like I use Environment.NewLine
instead of "\r\n".


I do, too - but only if I want the environment's 'new line' string.

If I actually want "\r\n" I use exactly that.
Nov 17 '05 #7
Tim Haughton <ti*********@gmail.com> wrote:
Right, and it's theoretically more flexible/portable, because you don't
rely on the fact that "" is the empty string. Hard to come up with a
practical example here, but the String.Empty syntax simply introduces that
additional layer of abstraction. Personally, I like the fact that it's
there and I use it, although it doesn't really make any difference to the
workings of your code (yet?).


You're right on the portability front, just like I use Environment.NewLine
instead of "\r\n".


No, there's no portability gain here. An empty string is an empty
string whatever platform you're on, whereas the new line varies by
system.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #8
Comments Inline
"Lasse Vågsæther Karlsen" <la***@vkarlsen.no> schrieb im Newsbeitrag
news:Oi**************@TK2MSFTNGP09.phx.gbl...
Oliver Sturm wrote:
Tim Haughton wrote:
can u write me
Why string.Empty is better then ""
<snip>

Also see:
http://blogs.msdn.com/brada/archive/.../22/49997.aspx

Looking at the IL generated, there's a difference, but both strings will


But there is no difference in the JIT-Compiled code!
be pulled out of the string interning cache so there will be no difference
at runtime.

--
Lasse Vågsæther Karlsen
http://www.vkarlsen.no/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2

Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jaime Wyant | last post by:
Will someone explain this to me? >>> "test".find("") 0 Why is the empty string found at position 0? Thanks! jw
4
by: Klaus Petersen | last post by:
Hi ng. I have a varchar field in my table, called Name. I wanna do a selection, which is ordered by whether this field is empty or not. E.g. something like: SELECT
0
by: Dana | last post by:
I am using the XMLTextWriter to build an XML string and pass it to the XMLDocument. When I get the data from SQL Server, some of the values passed to the XML are NULL in the database. When I try...
8
by: Peter Merwood | last post by:
I'm using some sample code from MSDN. The code includes the following statement: Dim content as = .Empty I'm not familiar with the use of the square brackets. Can someone please explain to...
10
by: =?Utf-8?B?RWxlbmE=?= | last post by:
I am surprised to discover that c# automatically converts an integer to a string when concatenating with the "+" operator. I thought c# was supposed to be very strict about types. Doesn't it seem...
10
by: Dave griffiths | last post by:
Hi all Using VB2005 on Vista with a Norwegian locale setup. The test program has 3 textboxes the sum held in txt3. Using the code below, txt2 conversion causes an error when it is left empty....
21
by: Sami | last post by:
string = "" or string = string.Empty? should is the proper way? Sami
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.