.NET 库具有String.IsNullOrEmpty(value As String)
.
我可以<stringValue>.IsNullOrEmpty()
通过简单的扩展方法创建更舒适:
<Extension>
Function IsNullOrEmpty(s As String) As Boolean
Return String.IsNullOrEmpty(s)
End Function
我的第一个快速理解是,这不是开箱即用的,因为它可以NullReferenceException
在null
. 直到我发现这是不正确的,因为Nothing
在 String 中变量被键入为字符串。
Dim s As String = Nothing
If s.IsNullOrEmpty() Then ... 'this will always return true, no exception thrown
使用默认表单String.IsNullOrEmpty(s)
而不是s.IsNullOrEmpty()
我缺少的表单是否有意义?
当然,在即时窗口中我不能输入
? Nothing.IsNullOrEmpty()
但无论如何这都是无稽之谈。这正常工作:
? CStr(Nothing).IsNullOrEmpty()