什么是空字符串的目的是什么? [英] What's the purpose of the empty string?

查看:244
本文介绍了什么是空字符串的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,作为一个开发者,并作为一个用户,我发现一个空字​​符串()无用和许多混乱的原因,这好像是说字符串==的char []

也许计算机需要空字符串,所以我想知道为什么。

  

参见:

     
      
  • 默认字符串初始化:null或空
  •   
  • <一个href="http://stackoverflow.com/questions/1626597/best-practice-should-functions-return-null-or-an-empty-object">Best做法:?如果函数返回null或一个空对象
  •   
解决方案

有人可能会争辩说,空字符串是的空对象模式的。安东尼指出,这是为了避免特殊情况和大量的如果秒。

To me, as a developer and as a user, I find the empty string ("") useless and the cause of much confusion, it's like saying string == char[]

Maybe computers need the empty string, so I'd like to learn why.

See also:

解决方案

One could argue that the empty string is an instance of the Null Object Pattern. As Anthony pointed out, this is used to avoid special cases and lots of ifs.

这篇关于什么是空字符串的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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