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

C# String IsNullOrEmpty Method Example

 In the C#, IsNullOrEmpty() is a string method which is used to check whether the specified string is null or an Empty string.

Syntax:

public static bool IsNullOrEmpty(String str)  

Parameter

str: it is a string parameter which is used to check string.

Return

It returns boolean value.

C# String IsNullOrEmpty() Method Example

using System;
public class Program
{
 public static void Main()
 {
    string str = "Hello FindAndSolve";
    string str1 = "";
    bool a = string.IsNullOrEmpty(str);
    bool b = string.IsNullOrEmpty(str1);
    Console.WriteLine(a);
    Console.WriteLine(b);
 }
}

Output

False

True

Another Example

using System;
public class Program
{   public static bool check(string strParam)
    {
      return (strParam == null || strParam == String.Empty) ? true : false;
    }
    // Main Method
    public static void Main(string[] args)
    {
        string str = "FindAndSolve";
        // or declare String str1.Empty;
        string str1 = "";
        string str2 = null;
        bool a = check(str);
        bool b = check(str1);
        bool c = check(str2);
        // same output as above program
        Console.WriteLine(a);
        Console.WriteLine(b);
        Console.WriteLine(c);
    }
}

Output

False

True

True