我确定我在这里遗漏了一些东西.对于某个项目,我需要检查字符串是否为空或 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)) {
...
}
这篇关于更简单的写空或空的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检查字符串是否为空How to check if String is null(如何检查字符串是否为空)
Equals(item, null) 或 item == nullEquals(item, null) or item == null(Equals(item, null) 或 item == null)
覆盖 == 运算符.如何与空值进行比较?Overriding == operator. How to compare to null?(覆盖 == 运算符.如何与空值进行比较?)
成员访问中的问号在 C# 中是什么意思?What does the question mark in member access mean in C#?(成员访问中的问号在 C# 中是什么意思?)
||(或)C# 中的 Linq 运算符The || (or) Operator in Linq with C#(||(或)C# 中的 Linq 运算符)
C# 空合并运算符等效于 C++C# null coalescing operator equivalent for c++(C# 空合并运算符等效于 C++)