How to convert a list to string in C#?


Declare a list.

List < string > l = new List < string > ();

Now, add elements to the list.

// elements
l.Add("Accessories");
l.Add("Footwear");
l.Add("Watches");

Now convert it into a string.

string str = string.Join(" ", l.ToArray());

Let us see the final code to convert a list to string in C# −

Example

using System;
using System.Collections.Generic;
class Demo {
   static void Main() {
      List < string > l = new List < string > ();
      // elements
      l.Add("Accessories");
      l.Add("Footwear");
      l.Add("Watches");
      string str = string.Join(" ", l.ToArray());
      Console.WriteLine(str);
   }
}

Updated on: 22-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements