【发布时间】:2022-06-10 21:29:49
【问题描述】:
我已经编写了下面的代码,其中我试图使用string.join() 方法将double 类型的数组转换为string 值。然后,我将字符串值作为属性添加到 XML 元素。
XElement element = new("TestNode");
double[] myDoubleArray = new double[2] { 0.001, 1.0 };
var stringValue = string.Join(" ", myDoubleArray);
element.Add(new XAttribute("Values", stringValue));
上面代码的输出是
<TestNode Values="0,001 1" />
可以看出,0.001的值已经写成0,001,因为我的系统语言是德语。
问题:如何在保持 InvariantCulture 的同时从 double 类型的数组(以最少的代码行数)创建一个空格分隔的字符串?
【问题讨论】:
标签: c# string invariantculture