Convert a list to a joined string of ints?

后端 未结 2 857
猫巷女王i
猫巷女王i 2020-12-16 14:51

I have an int array with the value 3,99,6. How do i convert the array into the string 3,99,6 with linq?

2条回答
  •  时光说笑
    2020-12-16 15:11

    Stefan's solution is correct, and pretty much required for .NET 3.5. In .NET 4, there's an overload of String.Join which takes an IEnumerable so you can use:

    string s = string.Join(",", list.Select(x => x.ToString());
    

    or even just:

    string s = string.Join(",", list);
    

提交回复
热议问题