How to get a comma separated string from an array
We can get a comma-separated string from an array using String.Join() method.
string[] animals = { "Cat", "Alligator", "Fox", "Donkey" };
var str = String.Join(",", animals);
In the same way, we can get a comma-separated string from the integer array.
int[] nums = { 1, 2, 3, 4 };
var str = String.Join(",", nums);
We can also get a comma separated string from the object array, as shown below.
Person[] people = {
new Person(){ FirstName="Steve", LastName="Jobs"},
new Person(){ FirstName="Bill", LastName="Gates"},
new Person(){ FirstName="Lary", LastName="Page"}
};
var str = String.Join(",", people.Select(p => p.FirstName) );
Thus, we can easily get the string with comma separated or any other separator from the array in C#.