Convert an array to string

前端 未结 3 371
悲哀的现实
悲哀的现实 2020-12-13 11:43

How do I make this output to a string?

List Client = new List();
foreach (string listitem in lbClients.SelectedItems)
{
    Clien         


        
相关标签:
3条回答
  • 2020-12-13 12:17

    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.

    0 讨论(0)
  • 2020-12-13 12:19

    My suggestion:

    using System.Linq;
    
    string myStringOutput = String.Join(",", myArray.Select(p => p.ToString()).ToArray());
    

    reference: https://coderwall.com/p/oea7uq/convert-simple-int-array-to-string-c

    0 讨论(0)
  • 2020-12-13 12:25

    You probably want something like this overload of String.Join:

    String.Join<T> Method (String, IEnumerable<T>)

    Docs:

    http://msdn.microsoft.com/en-us/library/dd992421.aspx

    In your example, you'd use

    String.Join("", Client);

    0 讨论(0)
提交回复
热议问题