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;
I wasn't going to chime in, but I'm seeing some wrong info getting tossed out here.
I, personally, prefer string.Empty
. That's a personal preference, and I bend to the will of whatever team I work with on a case-by-case basis.
As some others have mentioned, there is no difference at all between string.Empty
and String.Empty
.
Additionally, and this is a little known fact, using "" is perfectly acceptable. Every instance of "" will, in other environments, create an object. However, .NET interns its strings, so future instances will pull the same immutable string from the intern pool, and any performance hit will be negligible. Source: Brad Abrams.