The C# IsNullOrWhiteSpace function is employed to verify if the provided string is either null or composed solely of white-space characters, providing a Boolean outcome of True or False.
Signature
Example
public static bool IsNullOrWhiteSpace(String str)
Parameter
The variable str is a parameter of type string that is employed to verify if the string is null or contains only white spaces.
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