Updated on Kisan Patel
The IsNullOrEmpty
method is a very convenient method in that you can check if string is null or zero length.
The IsNullOrEmpty
method returns true if the string is Null or Empty Otherwise, this method returns false.
string stringTestResult = ""; if (String.IsNullOrEmpty(stringTestResult)) { Console.WriteLine("String is null or empty"); }
There is an another convenient method called String.IsNullOrWhiteSpace
that returns true if string is null, empty, or consists only of white-space characters otherwise false.
string stringTestResult = " "; if (String.IsNullOrWhiteSpace(stringTestResult)) { Console.WriteLine("String is null or empty or contain whitespace"); }