Export two different list into one string

前端 未结 1 1339
情深已故
情深已故 2021-01-28 02:59

I have two different lists I want to export in single CSV file in ASP.NET

string listToString1= string.Join(\",\", list1.ToArray());
string listToString2= string         


        
相关标签:
1条回答
  • 2021-01-28 03:16

    What you need is a Zip method:

    List<string> list1 = new List<string>() { "Collection ID", "id1", "id2" , "id3" };
    List<string> list2 = new List<string>() { "Collection Title", "Title1", "Title2", "Title3" };
    var result = string.Join(" ",list1.Zip(list2, (f,l) => f + "," + l));
    

    You need to make sure that you've added the System.Linq to your using directive though

    0 讨论(0)
提交回复
热议问题