Join collection of objects into comma-separated string

前端 未结 11 1350
无人共我
无人共我 2020-12-07 19:22

In many places in our code we have collections of objects, from which we need to create a comma-separated list. The type of collection varies: it may be a DataTable from whi

11条回答
  •  感动是毒
    2020-12-07 19:42

    Here's my favorite answer adapted to the question, and corrected Convert to ConvertAll:

    string text = string.Join(", ", Array.ConvertAll(table.Rows.ToArray(), i => i["title"]));
    

提交回复
热议问题