C# - 替换"." 以","为双倍价值

uzi*_*tmp 3 c# double replace comma

我必须阅读.txt并显示它.数据中的double值用"."写入.当我启用德语时,它不会将其解释为逗号.现在我尝试检查语言是否设置为德语并替换所有"." 用",".这些值存储在名为"_value"的数组中,但不起作用.这是代码:

 if ((System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName) == "de")
            {
                for (int i = 0; i < _value.Length; i++)
                {
                    String temp_var = Convert.ToString(_value[i]);
                    temp_var.Replace(".", ",");
                    _value[i] = Convert.ToDouble(temp_var);
                }
            }
Run Code Online (Sandbox Code Playgroud)

C.E*_*uis 5

您还可以提供转换完成的文化,而不是检查语言:

// Convert string to double from the invariant culture, which treats "." as decimal:
double d = Convert.ToDouble(_value[i], CultureInfo.InvariantCulture);

// Convert double to string using the current culture, which may happen to be German and uses a ",":
string s = Convert.ToString(d);

// Or convert double to string using the specific German culture:
string s = Convert.ToString(d, new CultureInfo("de-DE"));
Run Code Online (Sandbox Code Playgroud)

我不明白的是,显然_value数组已经是double[]- 所以这些更改必须在代码中提前完成,其中实际上会发生从字符串到double的转换.