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

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

    string is synonym for System.String type, They are identical.

    Values are also identical: string.Empty == String.Empty == ""

    I would not use character constant "" in code, rather string.Empty or String.Empty - easier to see what programmer meant.

    Between string and String I like lower case string more just because I used to work with Delphi for lot of years and Delphi style is lowercase string.

    So, if I was your boss, you would be writing string.Empty

提交回复
热议问题