Converting a List to a comma separated string

后端 未结 8 1419
深忆病人
深忆病人 2020-12-12 23:04

Is there a way to take a List and convert it into a comma separated string?

I know I can just loop and build it, but somehow I think some of you guys a more cool w

8条回答
  •  無奈伤痛
    2020-12-12 23:42

    Seems reasonablly fast.

    IList listItem = Enumerable.Range(0, 100000).ToList();
    var result = listItem.Aggregate(new StringBuilder(), (strBuild, intVal) => { strBuild.Append(intVal); strBuild.Append(","); return strBuild; }, (strBuild) => strBuild.ToString(0, strBuild.Length - 1));
    

提交回复
热议问题