Arunava Bhattacharjee
What is the difference between string.Empty and ""?Which one is best to use?
By Arunava Bhattacharjee in C# on Sep 24 2014
  • lakshmana poojary
    Sep, 2014 25

    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.

    • 4
  • Rahul Prajapat
    May, 2015 31

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

    • 1
  • Ajeet Mishra
    Sep, 2015 3

    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.

    • 0
  • Sreeni Dony
    Jul, 2015 22

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

    • 0
  • Pankaj  Kumar Choudhary
    May, 2015 23

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

    • 0
  • Kml Surani
    Apr, 2015 15

    "" is best

    • 0
  • Munesh Sharma
    Oct, 2014 1

    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.

    • 0
  • Vijay Kumar  Yadav
    Sep, 2014 25

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

    • 0
  • Arunava Bhattacharjee
    Sep, 2014 25

    Exactly...nice answer :)

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS