Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 array?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
216 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...