9
Reply

What is the difference between string.Empty and ""?Which one is best to use?

Arunava Bhattacharjee

Arunava Bhattacharjee

Sep 24, 2014
5.2k
0

    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 poojary
    September 25, 2014
    4

    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 Mishra
    September 03, 2015
    0

    "" is a constant.string.empty is the best option.

    Sreeni Dony
    July 22, 2015
    0

    String.Empty because it is a static variable, rather than "" which has to create a new string. So String.Empty is best .

    Rahul Prajapat
    May 31, 2015
    0

    String.Empty because it is a static variable, rather than "" which has to create a new string. So String.Empty is best ..........

    "" is best

    Kml Surani
    April 15, 2015
    0

    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 Sharma
    October 01, 2014
    0

    Really! its very helpful for memory efficiency ..............

    Vijay Kumar Yadav
    September 25, 2014
    0

    Exactly...nice answer :)

    Arunava Bhattacharjee
    September 25, 2014
    0