C# String IsNullOrWhiteSpace Method Example

In this source code example, we will demonstrate the usage of String.IsNullOrWhiteSpace() method in C# with an example.

The C# String.IsNullOrWhiteSpace() method is used to check whether the specified string is null, or consists only of white-space characters. It returns a boolean value either True or False.

C# String IsNullOrWhiteSpace Method Example

The following example demonstrates the use of the String.IsNullOrWhiteSpace() method:
using System;

public class StringDemo
{
    public static void Main(string[] args)
    {
        string s1 = "sourcecodeexamples";
        
        string s2 = null;
         
        string s3 = " ";
         
        bool b1 = string.IsNullOrWhiteSpace(s1);  
        bool b2 = string.IsNullOrWhiteSpace(s2);  
        bool b3 = string.IsNullOrWhiteSpace(s3); 
        
        Console.WriteLine(b1);       
        Console.WriteLine(b2);       
        Console.WriteLine(b3);       
        
    }

}

Output:

False
True
True

Related C# String Examples

References


Comments