Should we optimize or deprecate string.Empty
in C#?
#73123
-
There are 2 representation for an empty string in C#, // const string DefaultSomeValue = string.Empty; // error
const string DefaultSomeValue = ""; // OK
string someValue = "" + "foo " + "bar"; // Compiled to "foo bar" by Roslyn
string someValue2 = string.Empty + "foo " + "bar"; // Compiled to string.Concat(string.Empty, "foo bar") by Roslyn Should we allow
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Why do we need to optimize this? What's the benefit obtained? Why not just meet the runtime optimize this? |
Beta Was this translation helpful? Give feedback.
I don't see why that's the case, no. What's the tangible benefit to this? We have effectively infinite work and things that can be focused on. We should do things because of the real benefits they bring, otherwise, we're taking away time from much more beneficial things.
I don't think we care on the C# team. Use whichever you think is best in your code.
We're not making optimization decisions based on .NetFx. If you want optimized, use .Net Core (which is often multiple times faste…