用户登录
用户注册

分享至

更简单的写空或空的方法?

  • 作者: MISS佳
  • 来源: 51数据库
  • 2022-10-20

问题描述

我确定我在这里遗漏了一些东西.对于某个项目,我需要检查字符串是否为空或 null.

I'm sure I've missed something here. With a certain project I need to check if a string is empty or null.

有没有更简单的写法?

if(myString == "" || myString == null)
{
   ...

推荐答案

是的,有 String.IsNullOrEmpty 辅助方法已经用于:

Yes, there's the String.IsNullOrEmpty helper method for exactly this already:

if (String.IsNullOrEmpty(myString)) {
    ...
}
软件
前端设计
程序设计
Java相关