Comma “izing” a list of items

前端 未结 10 1683
我寻月下人不归
我寻月下人不归 2021-02-04 08:53

Given a list of strings, what is the best method for concatenating these strings into a comma separated list with no comma at the end. (VB.NET or C#) (Using either StringBuilder

10条回答
  •  隐瞒了意图╮
    2021-02-04 09:40

    Would you believe there's a class in the .NET framework which provides this functionality?

    public static string ListToCsv(List list)
            {
                CommaDelimitedStringCollection commaStr = new CommaDelimitedStringCollection();
    
                list.ForEach(delegate(T item)
                {
                    commaStr.Add(item.ToString());
                });
    
    
                return commaStr.ToString();
            }
    

提交回复
热议问题