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

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

    One difference is that if you use a switch-case syntax, you can't write case string.Empty: because it's not a constant. You get a Compilation error : A constant value is expected

    Look at this link for more info: string-empty-versus-empty-quotes

提交回复
热议问题