The C# IsNullOrWhiteSpace method is used to check whether the specified string is null, or consists only of white-space characters. It returns boolean value either True or False.
Signature
Example
public static bool IsNullOrWhiteSpace(String str)
Parameter
str: it is a string parameter which is used to check null, white-space in string.
Return
It returns boolean value.
C# String IsNullOrWhiteSpace Method Example
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#";
string s2 = "";
string s3 = " ";
bool b1 = string.IsNullOrWhiteSpace(s1);
bool b2 = string.IsNullOrWhiteSpace(s2);
bool b3 = string.IsNullOrWhiteSpace(s3);
Console.WriteLine(b1); // returns False
Console.WriteLine(b2); // returns True
Console.WriteLine(b3); // returns True
}
}
Output:
Output
False
True
True