转换列表<&诠释GT;到整数的加入字符串? [英] Convert a list<int> to a joined string of ints?

查看:120
本文介绍了转换列表<&诠释GT;到整数的加入字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和值3,99,6 int数组。如何将数组转换成字符串 3,99,6 使用LINQ?


解决方案

  INT []列表=新[] {3,99,6}; 
字符串s =的string.join(,,list.Select(X => x.ToString())ToArray的());

修改,C#4.0



使用C#4.0中,有 的另一个重载的string.join ,最终使传递一个的IEnumerable<串> 的IEnumerable< T> 直接。没有必要创建一个数组,而且也没有必要要求的ToString(),这是隐式调用:

 字符串s =的string.join(,清单); 

通过明确的格式化字符串:

 字符串s =的string.join(,list.Select(X => x.ToString(/*...*/)); 


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?

解决方案

int[] list = new [] {3, 99, 6};
string s = string.Join(",", list.Select(x => x.ToString()).ToArray());

Edit, C# 4.0

With C# 4.0, there is another overload of string.Join, which finally allows passing an IEnumerable<string> or IEnumerable<T> directly. There is no need to create an Array, and there is also no need to call ToString(), which is called implicitly:

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

With explicit formatting to string:

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

这篇关于转换列表&LT;&诠释GT;到整数的加入字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆