Click here to Skip to main content
15,907,000 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

May I know the difference between String.Empty and "", Nowadays we are using both, Which one is better? Please assist me,

Thank you
Posted

In the newer .NET versions, there is not really a difference, and there is no 'better' one. Use the one you prefer:
http://stackoverflow.com/questions/263191/in-c-should-i-use-string-empty-or-string-empty-or[^]
In .NET pre 2.0, "" creates a new object, while String.Empty does not. So if you use .NET pre 2.0, String.Empty is more efficient:
http://stackoverflow.com/questions/151472/what-is-the-difference-between-string-empty-and-empty-string[^]
 
Share this answer
 
v2
In .Net pre 2.0, "" creates an object while String.Empty creates no object. So it is more efficient to use String.Empty.


.Length == 0 is the fastest option, but .Empty makes for slightly cleaner code.

In version 2.0 and above of .Net, all occurrences of "" refer to the same string literal.

So "" is pretty equivalent to .Empty, but still not as fast as .Length == 0.

Taken from the following Stack Overflow answer of Brian R. Bondy: http://stackoverflow.com/a/151481[^]
 
Share this answer
 
v3
Comments
Manikandan MAC 1-Aug-14 6:49am    
Thank you, Could you say some coding tip like that, because it is very useful to build an quality software.
Pravuprasad 1-Aug-14 6:54am    
Ask what type of tip you want here, every member will help you?
Thomas Daniels 1-Aug-14 7:24am    
I added the source to your answer, because the license that Stack Overflow uses says that copying answers is allowed, but only with attribution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900