Add comma between values by using Linq

My values come from ComboBox:

2|722|742|762|77

I delete unnecessary characters as follows:

foreach (var item in checkListBox)
{
    string[] list = item.Split(
        new string[] { "2|" },
        StringSplitOptions.RemoveEmptyEntries);
}

My list values result:

"72"
"74"
"76"
"77"

My question is:

how can I get all of the above values in 1 row (next to each other) separated by comma like this:

72,74,76,77

?

Jon Skeet
people
quotationmark

It sounds like you just want string.Join:

string commaSeparated = string.Join(",", list);

(Note that this is not part of LINQ - it's not the same kind of "join" as for joining multiple sequences. It's joining several strings together with a separator.)

While you can do this in a single statement as per the currently accepted answer, I'd personally consider leaving your existing statement and having this as a separate step. It makes the code easier to both read and debug.

people

See more on this question at Stackoverflow