I would be happy if the class System.String had the field WhiteSpace, just like Empty. The field would represent the string with a single white space character.
I've seen may times in a code strings with a single white space character. Typically, when using concatenating strings. I wish instead of " ", there could be more elegant way to do it with string.WhiteSpace.
@olegburov so to make sure I understand, instead of eg
```c#
var result = foo + " " + bar + " " + baz;
you would prefer to write
```c#
var result = foo + string.WhiteSpace + bar + string.WhiteSpace + baz;
Is that right?
If the field is called string.WhiteSpace, it should be allowed to arbitrarily return anything for which string.IsNullOrWhiteSpace returns true, except null.
I wish instead of
" ", there could be more elegant way to do it withstring.WhiteSpace.
You could just define a proper constant like const string WhiteSpace = " "; and use that.
Personally I find " " more elegant and concise than the proposal, especially with regard to @jnm2's comment.
@danmosemsft yes, you got it right, but I would use the following example to show the benefits of string.WhiteSpace:
```c#
var result = new StringBuilder();
foreach (var item in SomeCollection)
{
result.Append(item.GetSomeResult());
result.Append(string.WhiteSpace);
}
```
@olegburov We could use the same argument to also propose adding String.Comma or String.Semicolon, because generating CSV data is also common.
foreach (var item in SomeCollection)
{
result.Append(item.GetSomeResult());
result.Append(string.Comma);
}
Myself I do not see the value of this. It makes code which seems quite readable, less readable. BTW wouldn't it be called string.Space ?
The compiler already interns string literals so it does not provide that benefit.
It's coming up on 2 years and there has been no recent activity on this issue. Is there still interest in this? Otherwise, we should close it.
I don't think this is something we should or would add. I think we can close it. Thanks.
Most helpful comment
Myself I do not see the value of this. It makes code which seems quite readable, less readable. BTW wouldn't it be called
string.Space?The compiler already interns string literals so it does not provide that benefit.