为什么没有Char.Empty像String.Empty? [英] Why is there no Char.Empty like String.Empty?

查看:395
本文介绍了为什么没有Char.Empty像String.Empty?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么原因吗?我问这是因为如果你需要使用大量的空字符,那么你会遇到同样的情况,当你使用大量的空字符串。



编辑:此用法的原因是:

  myString.Replace('c','')



因此请从myString中删除所有'c'实例。

解决方案

没有空字符这样的东西。最接近的可以是'\0',Unicodenull字符。既然你可以嵌入字符串文字或表达它自己很容易,为什么你想要一个单独的字段呢?同样,很容易混淆参数不适用于'\0'



如果你能给出一个例子你想要使用它,会更好,这可能有助于...


Is there a reason for this? I am asking this because if you needed to use lots of empty char, 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...

这篇关于为什么没有Char.Empty像String.Empty?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆