In C#, should I use string.Empty or String.Empty or “” to intitialize a string?

前端 未结 30 2493
挽巷
挽巷 2020-11-22 02:06

In C#, I want to initialize a string value with an empty string.

How should I do this? What is the right way, and why?

string willi = string.Empty;
         


        
30条回答
  •  北海茫月
    2020-11-22 02:47

    On http://blogs.msdn.com/b/brada/archive/2003/04/22/49997.aspx :

    As David implies, there 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. However, you should keep in mind the difference is so trival you will like never see it in your code...
    As for System.String.Empty or string.Empty or String.Empty... my care level is low ;-)

提交回复
热议问题