Interviews9 answers
What is the difference between string.Empty and ""?Which one is best to use?
9 Answers
The difference between string.Empty and "" is very small. String.empty will not create any object while "" will create a new object in the memory for the checking. Hence string.empty is better in memory management.
Ajeet MishraPosted Sep 3, 2015, 5:07 AM EDT
"" is a constant.string.empty is the best option.
Sreeni DonyPosted Jul 22, 2015, 1:26 AM EDT
String.Empty because it is a static variable, rather than "" which has to create a new string.
So String.Empty is best .
Rahul PrajapatPosted May 31, 2015, 7:37 PM EDT
String.Empty because it is a static variable, rather than "" which has to create a new string.
So String.Empty is best ..........
Pankaj Kumar ChoudharyPosted May 23, 2015, 8:02 AM EDT
In .Net pre 2.0, "" creates an object while String.Empty creates no object. So it is more efficient to use String.Empty.
Source of information
.Length == 0 is the fastest option, but .Empty makes for slightly cleaner code.
As @chadmyers mentioned, 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.
Munesh SharmaPosted Sep 30, 2014, 9:58 PM EDT
Really! its very helpful for memory efficiency ..............
Vijay Kumar YadavPosted Sep 25, 2014, 4:40 AM EDT
Exactly...nice answer :)
Arunava BhattacharjeePosted Sep 24, 2014, 11:03 PM EDT
Difference between String.Empty and “” are pretty small, but there is a difference. “” actually creates an object, it will likely be pulled out of the string intern pool, but still… while String.Empty creates no object… so if you are really looking for ultimately in memory efficiency, I suggest String.Empty.
lakshmana poojaryPosted Sep 24, 2014, 10:16 PM EDT





