C# Tutorial C# Advanced C# References

C# String - IsNullOrEmpty() Method



The C# IsNullOrEmpty() method is used to check the specified string for null or empty. It returns true if the specified string is null or empty, else returns false.

Syntax

public static bool IsNullOrEmpty(string value);

Parameters

value Specify the string which need to be tested.

Return Value

Returns true if the specified string is null or empty, else returns false.

Exception

NA.

Example:

In the example below, IsNullOrEmpty() method is used to check the string called MyStr for null or empty.

using System;

class MyProgram {
  static void Main(string[] args) {
    string MyStr;

    MyStr = "Hello";
    Console.WriteLine(String.IsNullOrEmpty(MyStr)); 
    MyStr = "";
    Console.WriteLine(String.IsNullOrEmpty(MyStr)); 
    MyStr = null;
    Console.WriteLine(String.IsNullOrEmpty(MyStr)); 
  }
}

The output of the above code will be:

False
True
True

❮ C# String Methods