Convert an Array to String
How Do I Make This Output to a String? List Client = New List(); Foreach (String Listitem in lbClients. Selecteditems) { Client. Add(Listitem); } 3 4 Answers...
How do I make this output to a string?
List<string> Client = new List<string>();
foreach (string listitem in lbClients.SelectedItems)
{
Client.Add(listitem);
}
4 Answers
You can join your array using the following:
string.Join(",", Client);
Then you can output anyway you want. You can change the comma to what ever you want, a space, a pipe, or whatever.
You probably want something like this overload of String.Join:
String.Join<T> Method (String, IEnumerable<T>)
Docs:
In your example, you'd use
String.Join("", Client);
My suggestion:
using System.Linq;
string myStringOutput = String.Join(",", myArray.Select(p => p.ToString()).ToArray());
reference:
You can write like this:
string[] arr = { "Miami", "Berlin", "Hamburg"};
string s = string.Join(" ", arr);