C# 从字符串转换为双精度在C中不起作用# 公共字符串读取文件() { 字符串文本; 使用(var streamReader=newstreamreader(“c:/aaa/balance.txt”,Encoding.UTF8)); { text=streamReader.ReadToEnd(); } 返回文本; } 公共双sumOfPlus() { 双和=0; 字符串text=readFile(); 字符串[]arr=text.Split(','); 对于(int i=0;i
我无法获得总和的输出,文件中的数字是有效的。C# 从字符串转换为双精度在C中不起作用# 公共字符串读取文件() { 字符串文本; 使用(var streamReader=newstreamreader(“c:/aaa/balance.txt”,Encoding.UTF8)); { text=streamReader.ReadToEnd(); } 返回文本; } 公共双sumOfPlus() { 双和=0; 字符串text=readFile(); 字符串[]arr=text.Split(','); 对于(int i=0;i,c#,C#,我无法获得总和的输出,文件中的数字是有效的。 我在转换行中发现一个错误,它说:这不是complibate格式模式 public string readFile() { string text; using (var streamReader = new StreamReader("c:/aaa/balance.txt",Encoding.UTF8)); { text = streamReader.Re
我在转换行中发现一个错误,它说:这不是complibate格式模式
public string readFile()
{
string text;
using (var streamReader = new StreamReader("c:/aaa/balance.txt",Encoding.UTF8));
{
text = streamReader.ReadToEnd();
}
return text;
}
public double sumOfPlus()
{
double sum = 0;
string text = readFile();
string[] arr = text.Split(',');
for (int i = 0; i < arr.Length; i++)
{
sum += Convert.ToDouble(arr[i]);
}
return sum;
}
}
代替
string[] arr = text.Split(new []{",", " "},StringSplitOptions.RemoveEmptyEntries);
itws-not-complibate模式
确定不是此消息…文件中的输入格式有缺陷。我需要做什么?把它改成浮动?非常感谢,我不知道这个选项。不客气。现在你可以检查问题的答案了。
string[] arr = text.Split(',');