![]() |
VOOZH | about |
In C#, IsNullOrEmpty() is a string method. It is used to check whether the specified string is null or an Empty string. A string will be null if it has not been assigned a value. A string will be empty if it is assigned “” or String.Empty (A constant for empty strings).
Example 1: Using IsNullOrEmpty() to check whether the string is Null or empty.
"" is null or empty: True "Geek" is null or empty: False
public static bool IsNullOrEmpty(String str)
Note: The IsNullOrEmpty method is used to check whether a string is either null or empty ("").
A simple alternative to IsNullOrEmpty() can be written as:
return s == null || s == String.Empty;
This alternative works similarly but lacks the built-in optimization and clarity of IsNullOrEmpty().
Example 2: Demonstrating a similar method to IsNullOrEmpty() and its internal workings.
False True True