Merging a String Array to a Comma delimited String (foreach)

string str = "";

// loop though an array and create a string
// delimited with commas
foreach (string s in fieldNames)
{
str += s;

// if this not the last item in the array
// append a comma to end of the string.
if (s != fieldNames[fieldNames.Length - 1])
{
str += ", ";
}
}

source

Leave a Reply