Is there a reason for this? I am asking because if you needed to use lots of empty chars then you get into the same situation as you would when you use lots of empty strings.
Edit: The reason for this usage was this:
myString.Replace ('c', '')
So remove all instances of 'c's from myString.
There's no such thing as an empty char. The closest you can get is
'\0'
, the Unicode "null" character. Given that you can embed that within string literals or express it on its own very easily, why would you want a separate field for it? Equally, the "it's easy to confuse""
and" "
" arguments don't apply for'\0'
.If you could give an example of where you'd want to use it and why you think it would be better, that might help...
A char, unlike a string, is a discrete thing with a fixed size. A string is really a container of chars.
So, Char.Empty doesn't really make sense in that context. If you have a char, it's not empty.
Use
Char.MinValue
which works the same as '\0'. But be careful it is not the same asString.Empty
.use
A char is a value type, so its value cannot be null. (Unless it is wrapped in a Nullable container).
Since it can't be null, in contains some numeric code and each code is mapped to some character.
Easiest way to blanket remove a character from string is to Trim it
cl = cl.Trim(' ');
Removes all of the spaces in a string