What is the difference between String.Empty and “” (empty string)?

后端 未结 17 1987
礼貌的吻别
礼貌的吻别 2020-11-22 03:25

In .NET, what is the difference between String.Empty and \"\", and are they interchangable, or is there some underlying reference or Localization i

17条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 04:26

    When you're visually scanning through code, "" appears colorized the way strings are colorized. string.Empty looks like a regular class-member-access. During a quick look, its easier to spot "" or intuit the meaning.

    Spot the strings (stack overflow colorization isn't exactly helping, but in VS this is more obvious):

    var i = 30;
    var f = Math.Pi;
    var s = "";
    var d = 22.2m;
    var t = "I am some text";
    var e = string.Empty;
    

提交回复
热议问题