IEnumerable to string

前端 未结 7 2137
既然无缘
既然无缘 2021-02-04 23:55

I have a DataTable that returns

IDs
,1
,2
,3
,4
,5
,100
,101

I want to convert this to single string value, i.e:

,1,2,3,4,5,100         


        
7条回答
  •  别跟我提以往
    2021-02-05 00:36

    You can cheat with this:

    String output = "";
    _tbl.AsEnumerable().Select(x => output += x).ToArray(); 
    // output now contains concatenated string
    

    Note ToArray() or similar is needed to force the query to execute.

    Another option is

    String output = String.Concat(_tbl.AsEnumerable().Select(x=>x).ToArray());
    

提交回复
热议问题