find and solve || findandsolve.com
Please wait.....

String IsNullOrWhiteSpace Method Example in C#

In the c# String.IsNullOrEmpty() method is used built-in method of String class and it is used to check whether the specified string is null or an empty string ("").It returns boolean value either True or False.

Syntax

The syntax is as follows−

public static bool IsNullOrEmpty (string val)

C# String IsNullOrWhiteSpace() Method Example

using System;
public class Program
{
    // Main Method
    public static void Main(string[] args)
    {
       string str = "Hello FindAndSolve";
       string str1 = "";
       string str2 = " ";
       bool a = string.IsNullOrWhiteSpace(str);
       bool b = string.IsNullOrWhiteSpace(str1);
       bool c = string.IsNullOrWhiteSpace(str2);
       Console.WriteLine(a);//returns False
       Console.WriteLine(b);//returns True
       Console.WriteLine(c);// returns True
    }
}

Output

False

True

True