CSV string handling

后端 未结 13 879
北荒
北荒 2020-12-28 16:44

Typical way of creating a CSV string (pseudocode):

  1. Create a CSV container object (like a StringBuilder in C#).
  2. Loop through the strings you want to ad
13条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 16:59

    You could use LINQ to Objects:

    string [] strings = contactList.Select(c => c.Name).ToArray();
    string csv = string.Join(",", strings);
    

    Obviously that could all be done in one line, but it's a bit clearer on two.

提交回复
热议问题