Csharp/C#教程:无法将List ‘隐式转换为’double’分享


无法将List ‘隐式转换为’double’

继续投掷,我的代码的这部分有什么问题,当我想返回单元格时收到此错误不能隐式地将类型’System.Collections.Generic.List’转换为’double’:

public double readFileToList(string Path) { var cells = new List(); 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 。 这会导致您看到的错误。


编辑

确认看你的编辑,这是你的问题。 将函数的返回类型更改为List ,您将很高兴! 您的代码应如下所示:

上述就是C#学习教程:无法将List ‘隐式转换为’double’分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 public List readFileToList(string Path) { var cells = new List(); 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; } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/951167.html

(0)
上一篇 2021年11月18日
下一篇 2021年11月18日

精彩推荐