VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/c-sharp-isnullorwhitespace-method/

⇱ C# | IsNullOrWhiteSpace() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C# | IsNullOrWhiteSpace() Method

Last Updated : 11 Jul, 2025
In C#, IsNullOrWhiteSpace() is a string method. It is used to check whether the specified string is null or contains only white-space characters. A string will be null if it has not been assigned a value or has explicitly been assigned a value of null. Syntax:
public static bool IsNullOrWhiteSpace(String str) 
Explanation: This method will take a parameter which is of type System.String and this method will return a boolean value. If the method's parameter list is null or String.Empty, or only contains white-space characters then return True otherwise return False. Example:
Input : str = null // initialize by null value
 String.IsNullOrWhiteSpace(str)
Output: True

Input : str = " " // initialize by whitespace
 String.IsNullOrWhiteSpace(str)
Output: True
Program: To demonstrate the working of the IsNullOrWhiteSpace() Method :
Output:
True
True
True
True
True
False
Note: There is a alternative code of IsNullOrWhiteSpace() method as follows:
return String.IsNullOrEmpty(str) || str.Trim().Length == 0;
Program: To demonstrate IsNullOrEmpty() method’s alternative
Comment
Article Tags:

Explore