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

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

    string mystring = "";
    ldstr ""
    

    ldstr pushes a new object reference to a string literal stored in the metadata.

    string mystring = String.Empty;
    ldsfld string [mscorlib]System.String::Empty
    

    ldsfld pushes the value of a static field onto the evaluation stack

    I tend to use String.Empty instead of "" because IMHO it's clearer and less VB-ish.

提交回复
热议问题