Use IsNullOrEmpty

Converts one or more expressions that test a string for null (Nothing in Visual Basic) or empty values into a single call to String.IsNullOrEmpty.

Availability

Available from the context menu or via shortcuts:

  • when the caret is on an Boolean expression that checks whether a string variable is a null reference or empty.

Notes

  • Expressions can check for an empty string by comparing to String.Empty or by checking the string's length.
  • The selected expression doesn't have to check for both a null reference and zero length. Use IsNullOrEmpty becomes available if at least one criteria is being checked.

Example

private string TestMethod(string param)
{if (param == null)
        return "Empty";
    return "Not Empty";
}
Private Function TestMethod(ByVal param As String) As StringIf param = Nothing Then
        Return "Empty"
    End If
    Return "Not Empty"
End Function

Result:

private string TestMethod(string param)
{if (String.IsNullOrEmpty(param))
        return "Empty";
    return "Not Empty";
}
Private Function TestMethod(ByVal param As String) As StringIf String.IsNullOrEmpty(param) Then
        Return "Empty"
    End If
    Return "Not Empty"
End Function

Screenshot

rsIsNullOrEmpty