三种常用的字符串判空串方法:
  • Length法:bool isEmpty = (str.Length == 0);
  • Empty法:bool isEmpty = (str == String.Empty);
  • General法:bool isEmpty = (str == "");

实践证明用Length方法判空是最快的(在32位系统上,System.Int32运算最快了),注意只有字符串不为null的前提下,.NET才会进一步计算s.Length是否为0,所以一般常用 if( (s == null) || (s.Length == 0) ) 进行判断。

相关文章:

  • 2021-12-04
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-12-04
  • 2021-07-28
猜你喜欢
  • 2021-12-04
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-12-04
相关资源
相似解决方案