473,767 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why string.Empty is better then ""

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

bye

Nov 17 '05 #1
8 13595
"monu" <gt*****@gmail. com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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****@sturmne t.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.New Line
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***@vk arlsen.no
PGP KeyID: 0x2A42A1C2
Nov 17 '05 #6
Tim Haughton <ti*********@gm ail.com> wrote:
You're right on the portability front, just like I use Environment.New Line
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*********@gm ail.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.New Line
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.co m>
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******** ******@TK2MSFTN GP09.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***@vk arlsen.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
2147
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
5819
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
2269
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 and run an update to database using the same XML string, (using SQL parameters to pass the selectsinglenode), the XML always shows the NULL values as an empty string "". This is then updating the database with an empty value rather than keeping...
8
4861
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 me what the difference between "Dim content as " and "Dim content as String". Thanks. Peter,
10
13641
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 like c# is breaking its own rules? This works: int b = 32; string a = "ABC " + b; Result: a = "ABC 32"
10
26909
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. The code in txt1 works OK but I am asking is there a better way of coding this Public Class Main
21
2980
by: Sami | last post by:
string = "" or string = string.Empty? should is the proper way? Sami
0
9571
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9405
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10013
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9960
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8838
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7383
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3930
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.