Convert List object to string C#

Convert List object to string C#

How to convert a list to string in C#?

CsharpProgrammingServer Side Programming



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);
}
}

raja

Ankith Reddy

Published on 20-Aug-2018 13:40:28

Previous Page Print Page

Next Page

Video liên quan

admin