List to CSV RRS feed

  • Question

  • Hello,

    I have a Linq query which returns items of

         List<Tag> Tags = new List<Tag> (from t in database.Tags
                                                            where t.Category = MyCategory).ToList(); 

    Each tag has three properties: ID, Name and Category 

    I need to convert this list to a CSV string of the Tag names in the list. How can I do this? 

    I have done before the conversion from CSV to List:
    List<Tag> Tags = MyCSVTags.Split(',').Select(t => new Tag { Name = t.Trim() }).ToList(); 

    But I am having problems in the List > CSV conversion. 

    Could someone, please, help me out? 

    Monday, August 25, 2008 12:38 PM


  • You could use string.Join().


    string.Join(', ", Tags.Select(t => t.Name).ToArray())


    Monday, August 25, 2008 3:54 PM