Finding Empty or Null string at once using C#

C# provide a functionality to check if a string is null or empty by single command. string have a internal function IsNullOrEmpty(), just pass the string in it and will return the true either it is null or empty.

Please use the below code Snippet to find it out.

using System;

namespace ConsoleTalk
{
    class Programs
    {
        static void Main(string[] args)
        {
            string sNull = null;
            string sEmpty = "";

            if (string.IsNullOrEmpty(sNull))
                Console.WriteLine("String is Null or Empty.");

            if (string.IsNullOrEmpty(sEmpty))
                Console.WriteLine("String is Null or Empty.");

            Console.ReadLine();
        }
    }

Thanks for reading this article.

Ebook Download
View all
Learn
View all