Null String in C#

In this article we will discuss about the Null string.
  • 3355

A null string is a string variable that has not been initialized yet and has a null value. If you try to call any methods or properties of a null string, you will get an exception. A null string valuable is exactly same as any other variable defined in your code. A null string is typically used in string concatenation and comparison operations with other strings.

The following code example shows how to use a null string.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
    class Program
        static void Main(string[] args)
            string nullStr = null;
            string empStr = string.Empty;
            string name = "Mahesh Chand";
            if ((name != nullStr) || (name != empStr))
                Console.WriteLine(name + " is neither null nor empty");

Further Readings
You may also want to read these related articles.
Ask Your Question 
Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.