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

后端 未结 17 1519
礼貌的吻别
礼貌的吻别 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:20

    I tend to use String.Empty rather than "" for one simple, yet not obvious reason: "" and "" are NOT the same, the first one actually has 16 zero width characters in it. Obviously no competent developer is going to put and zero width characters into their code, but if they do get in there, it can be a maintenance nightmare.

    Notes:

    • I used U+FEFF in this example.

    • Not sure if SO is going to eat those characters, but try it yourself with one of the many zero-width characters

    • I only came upon this thanks to https://codegolf.stackexchange.com/

提交回复
热议问题