简体   繁体   English

将字符串值传递给双精度数组C#

[英]passing string value to double array c#

I currently have a application that reads back the contents of the text file in a string. 我目前有一个应用程序,该应用程序以字符串形式读回文本文件的内容。 I want to put all those values in a double array I have created but can't seem to get it to work here is my code : 我想将所有这些值放入我创建的双精度数组中,但似乎无法使其正常工作,这是我的代码:

using (StreamReader sr = new StreamReader("test.txt"))
{
    String line =  sr.ReadToEnd();
    x = doubles;
    Console.WriteLine(x);
}

Everytime I run it I get the error "file could not be read: input string was not in a correct format" Does anyone have any idea whats wrong? 每次运行它时,我都会收到错误消息“无法读取文件:输入字符串的格式不正确”,有人知道有什么问题吗?

bool bSuccess;
double value;
bSuccess = double.TryParse("3.14", out value);

确保为StreamReader传递文件路径,仅声明没有明显位置的“ test.txt”就不会访问您试图读取的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM