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

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

    In .NET prior to version 2.0, "" creates an object while string.Empty creates no objectref, which makes string.Empty more efficient.

    In version 2.0 and later of .NET, all occurrences of "" refer to the same string literal, which means "" is equivalent to .Empty, but still not as fast as .Length == 0.

    .Length == 0 is the fastest option, but .Empty makes for slightly cleaner code.

    See the .NET specification for more information.

提交回复
热议问题