C# Tutorial C# Advanced C# Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

C# - String IsNullOrEmpty() Method



The C# string 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

5