I want to convert the double array into comma separated string. Is it doable with lambda expression:
double [] test = new double [] {1 ,2, 3} ;
for example, I want to convert above array in comma separated string using lambda expression.
Try this .Net version 4+
var result = String.Join(",", test);
read more about String.Join
.
It's not lambda expression, but I think that this is what you were looking for. Lamda expression are just delegates, so you don't need lambda here :)
EDIT:
for version .Net < 4.0 String.Join
accepts only string[]
(thanks @SonerGönül) and you need to use this:
var result = String.Join(",", test.Select(x=>x.ToString()).ToArray());
which will convert double [] test
to string array. Example
如果您需要以特殊方式格式化双打,可以这样:
var result = String.Join(",", test.Select(d => d.ToString("000000")));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.