the difference between string.Empty and null

G

Guest

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.
 
B

bruce barker

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.
 
S

Scott Allen

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.
 
K

Kevin Spencer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top