如何将字符串数组更改为字符串而不使用循环子句?它可以由LINQ实现吗?

时间:2012-03-07 01:34:37

标签: c# linq

  

输入:

  var pList=new []{"a","b","c"}; 
  

输出:

 string pListRet="a,b,c";

我知道它可以像JS一样快速实现pList.Join(","); 但它可以用C#实现吗?

1 个答案:

答案 0 :(得分:7)

You don't need Linq for that

var pList=new []{"a","b","c"};
string pListRet = String.Join(",",pList)

如果你真的真的想要使用linq,这可行:

var pList=new []{"a","b","c"}; 

string pListRet = pList.Aggregate((t,s) => t+(t==""?"":",")+s);