How to declare an empty string array in C#?


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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 20-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements