.NET libraries have String.IsNullOrEmpty(value As String)
.
I can create more comfortable <stringValue>.IsNullOrEmpty()
by simple extension method:
<Extension>
Function IsNullOrEmpty(s As String) As Boolean
Return String.IsNullOrEmpty(s)
End Function
My fist quick understanding was that this was not implemented out-of-the-box because it can throw NullReferenceException
in case of null
. Until I found this is not true, because Nothing
in String variable is typed as string.
Dim s As String = Nothing
If s.IsNullOrEmpty() Then ... 'this will always return true, no exception thrown
Is there point in having default form String.IsNullOrEmpty(s)
instead of s.IsNullOrEmpty()
which I am missing?
Of course, in Immediate Window I cannot type
? Nothing.IsNullOrEmpty()
but it is nonsense anyway. This works normally:
? CStr(Nothing).IsNullOrEmpty()