Is there a named constant like string.Space to replace ""

Using string.Emptyinstead is ""really nice and make the code more understandable. I am wondering if there is a good constant to replace " ". I found some ideas, such as using string.Empty.PadLeft(1)or string.Empty.PadRight(1), but I don't like it.

For the situation it would be useful to use string.Spaceinstead " ".

(Edited after comments)

To make my problem more clear:

In multicultural situations, there should be no code, for example "Can not open the file". String literals should be transferred to the resource file and then used as Resources.CanNotOpenTheFile.

To make sure this happens seems like a good rule to not have string literals in your code. Thus, looking at the code at a glance, you can quickly find bad implementations. I think this is a good explanation of why I am trying not to use "in code.

+5
source share
2 answers

No, but you can define your own.

public static class MyString 
{
    public const string Space = " ";
}

Then use it like:

Console.Write("Test" + MyString.Space + "Text");

EDIT But you shouldn't, IMO (and based on comments from Mark Gravel and PaulRuane), as this will make the code less readable

+3
source

Use the char constant, there is no need to use the string recommended by Habib.

public static class StringTools
{
    public const char Whitespace = ' ';
}
+1
source

All Articles