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

前端 未结 30 2519
挽巷
挽巷 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:35

    String.Empty and string.Empty are equivalent. String is the BCL class name; string is its C# alias (or shortcut, if you will). Same as with Int32 and int. See the docs for more examples.

    As far as "" is concerned, I'm not really sure.

    Personally, I always use string.Empty.

提交回复
热议问题