更简单的写空或空的方法? [英] Easier way of writing null or empty?

查看:22
本文介绍了更简单的写空或空的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定我在这里遗漏了一些东西.对于某个项目,我需要检查字符串是否为空或 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)) {
    ...
}

这篇关于更简单的写空或空的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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