Does Array.ToString() provide a useful output?

前端 未结 6 1020
北海茫月
北海茫月 2020-12-03 13:31

If I have an array and perform a ToString() does that just string together the array values in one long comma seperated string or is that not possible on an arr

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 13:51

    Option 1

    If you have an array of strings, then you can use String.Join:

    string[] values = ...;
    
    string concatenated = string.Join(",", values);
    

    Option 2

    If you're dealing with an array of any other type and you're using .NET 3.5 or above, you can use LINQ:

    string concatenated = string.Join(",",
                              values.Select(x => x.ToString()).ToArray());
    

提交回复
热议问题