Use string.IsNullOrEmpty
- 2 minutes to read
Purpose
Converts an expression that checks whether a string is null or empty to the string.IsNullOrEmpty method call. This shortens the code and increases code performance.
Availability
Available when the cursor is within an expression checking whether a string is null or empty.
Usage
Place the caret on an expression against a string checking whether it is null or empty.
NOTE
The blinking cursor shows the caret's position at which the Refactoring is available.
- Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
- Select Use string.IsNullOrEmpty from the menu.
After execution, the Refactoring replaces the logical expression with the string.IsNullOrEmpty method call.
public bool AddRecord(string name, object data) {
if (string.IsNullOrEmpty(name) || data == null)
return false;
//...
return true;
}
See Also