String Join() method

The Join () method in strings concatenates all the elements of a string array, using the specified separator between each element.

In the below example we have a multi-line string and we have set the separator as “
” −

", starray);


The following is the complete example −

 Live Demo

using System;

namespace StringApplication {

   class StringProg {
      static void Main(string[] args) {
         string[] starray = new string[]{"Down the way nights are dark",
            "And the sun shines daily on the mountaintop",
            "I took a trip on a sailing ship",
            "And when I reached Jamaica",
            "I made a stop"};

         string str = String.Join("
", starray);          Console.WriteLine(str);       }    } }


Down the way nights are dark
And the sun shines daily on the mountain top
I took a trip on a sailing ship
And when I reached Jamaica
I made a stop

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 27-Mar-2020


Kickstart Your Career

Get certified by completing the course

Get Started