How to declare an empty string array in C#?

CsharpProgrammingServer Side Programming

In C#, you can use strings as an array of characters, However, more common practice is to use the string keyword to declare a string variable. The string keyword is an alias for the System.String class.

To declare an empty string.

string[] arr = new string[] {}; // empty string

Now let us see what will happen when we will print this empty string.

Example

 Live Demo

using System;

namespace Demo {

   class Program {

      static void Main(string[] args) {

         string[] arr = new string[] {}; // empty string

         string res = String.Join(" ", arr);
   
         // let us now print the empty string
         Console.WriteLine("This won't print any message since its an empty string {0}", res);
      }
   }
}

Output

This won't print any message since its an empty string
raja
Published on 06-Aug-2018 12:33:43
Advertisements