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