C# 无法将System.IO.Streamreader类型转换为double
我必须从系统中加载一个文本文件,但出现以下错误: 无法将System.IO.Streamreader类型转换为doubleC# 无法将System.IO.Streamreader类型转换为double,c#,C#,我必须从系统中加载一个文本文件,但出现以下错误: 无法将System.IO.Streamreader类型转换为double 将变量conv声明为double,然后尝试为其分配StreamReader 请阅读提供的MSDN文章,了解如何使用该文件。streamreader就是阅读器,您实际上需要.Read()来获取该文件 using (TextReader reader = new StreamReader("C:\blabla.txt")) { //Create a reader - t
将变量
conv
声明为double
,然后尝试为其分配StreamReader
请阅读提供的MSDN文章,了解如何使用该文件。streamreader就是阅读器,您实际上需要.Read()来获取该文件
using (TextReader reader = new StreamReader("C:\blabla.txt"))
{
//Create a reader - the using ensures that the system cleans up when we're done.
//Read the whole file as a single string
string fileContents = reader.ReadToEnd();
//Parse the string to a double
double conv= Double.Parse(fileContents);
}
实际上,它应该是
Dispose
d,理想情况下使用块。开始学习好的实践永远都不会太早。非常感谢你们的反应太快,非常感谢。现在如果我使用此im,我会收到以下错误:“找不到命名空间TextReader,是否缺少程序集引用,以及StreamReader”对于未来的问题,请记住,您的问题不需要关于公司或您自己的背景故事。它应该包含3点:描述问题(包括错误消息)、您迄今为止的尝试以及预期+实际输出。大多数其他东西都是杂乱无章的。好吧。我不知道。谢谢,因为如果我不能将它描述为double,它就不能得到/by double,因为我也需要十进制值,所以我没有办法不将它描述为double
using (TextReader reader = new StreamReader("C:\blabla.txt"))
{
//Create a reader - the using ensures that the system cleans up when we're done.
//Read the whole file as a single string
string fileContents = reader.ReadToEnd();
//Parse the string to a double
double conv= Double.Parse(fileContents);
}