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;
It is totally a code-style preference, do to how .NET handles strings. However, here are my opinions :)
I always use the BCL Type names when accessing static methods, properties and fields: String.Empty
or Int32.TryParse(...)
or Double.Epsilon
I always use the C# keywords when declaring new instances: int i = 0;
or string foo = "bar";
I rarely use undeclared string literals as I like to be able to scan the code to combine them into reusable named constants. The compiler replaces constants with the literals anyway so this is more of a way to avoid magic strings/numbers and to give a little more meaning to them with a name. Plus changing the values is easier.