C# String IsNullOrEmpty Method Example

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

The C# String.IsNullOrEmpty() method is used to check whether the specified string is null or an empty string. It returns a boolean value either true or false.

C# String IsNullOrEmpty Method Example

The following example demonstrates the use of the String.IsNullOrEmpty() method:

using System;

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

}

Output:

False
True
True

Related C# String Examples

References




Comments