不断抛出,我的代码的这一部分出了什么问题,当我想返回单元格时,我收到此错误
无法将类型 'System.Collections.Generic.List' 隐式转换为 'double' :
public double readFileToList(string Path)
{
var cells = new List<double>();
string path = label3.Text;
if (File.Exists(path))
{
double temp = 0;
cells.AddRange(File.ReadAllLines(path)
.Where(line => double.TryParse(line, out temp))
.Select(l => temp)
.ToList());
int totalCount = cells.Count();
cellsNo.Text = totalCount.ToString();
}
return cells;
}
如果没有看到你的整个函数,很难确定,但我的猜测是你将函数的返回类型设置为double
代替List<double>
。这会导致您看到的错误。
Edit
确认查看您的编辑,这是您的问题。将函数的返回类型更改为List<double>
你就可以出发了!您的代码应如下所示:
public List<double> readFileToList(string Path)
{
var cells = new List<double>();
string path = label3.Text;
if (File.Exists(path))
{
double temp = 0;
cells.AddRange(File.ReadAllLines(path)
.Where(line => double.TryParse(line, out temp))
.Select(l => temp)
.ToList());
int totalCount = cells.Count();
cellsNo.Text = totalCount.ToString();
}
return cells;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)