Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > the difference between string.Empty and null

Reply
Thread Tools

the difference between string.Empty and null

 
 
=?Utf-8?B?QXNoYQ==?=
Guest
Posts: n/a
 
      11-02-2004
greetings, i have some questions below, what are the differences between

private string _strVal = string.Empty; and _strVal = null;

does the string.Empty; allocate memory for it? how about _strVal = ""

thanks for enlightening me on this.
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      11-02-2004
string.Empty points to one string that equal "". due to literal pooling,
there is only one copy per assembly for "". null is a different value, and
takes no gc memory.


"Asha" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> greetings, i have some questions below, what are the differences between
>
> private string _strVal = string.Empty; and _strVal = null;
>
> does the string.Empty; allocate memory for it? how about _strVal = ""
>
> thanks for enlightening me on this.



 
Reply With Quote
 
 
 
 
Scott Allen
Guest
Posts: n/a
 
      11-02-2004
To expand on Bruce's comment:

String.Empty is a valid instance of the string class, you can invoke
the Length property (and get back a value of 0). A null reference does
not refer to a valid object.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Mon, 1 Nov 2004 17:09:01 -0800, "Asha"
<(E-Mail Removed)> wrote:

>greetings, i have some questions below, what are the differences between
>
>private string _strVal = string.Empty; and _strVal = null;
>
>does the string.Empty; allocate memory for it? how about _strVal = ""
>
>thanks for enlightening me on this.


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      11-02-2004
To expand on Scott's comment:

A string is actually an array of char. The array is terminated with a null
zero character (ASCII 0 or \0). The null zero does not count when referring
to the length of the string. It is simply the terminator character for the
array. A null string is a variable that is not initialized and points to
null. An empty string is a variable that points to an array with only a null
zero in it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:(E-Mail Removed)...
> To expand on Bruce's comment:
>
> String.Empty is a valid instance of the string class, you can invoke
> the Length property (and get back a value of 0). A null reference does
> not refer to a valid object.
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
> On Mon, 1 Nov 2004 17:09:01 -0800, "Asha"
> <(E-Mail Removed)> wrote:
>
> >greetings, i have some questions below, what are the differences between
> >
> >private string _strVal = string.Empty; and _strVal = null;
> >
> >does the string.Empty; allocate memory for it? how about _strVal = ""
> >
> >thanks for enlightening me on this.

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between '\0' and NULL lak C Programming 8 11-27-2007 10:12 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
difference between null object and null string gokul.b@gmail.com Java 16 10-12-2005 06:43 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
null and NULL: is there any difference? RHNewBie C Programming 17 09-26-2003 02:20 PM



Advertisments