无法隐式转换List< double>' “加倍” [英] Cannot implicitly convert List<double>' to 'double'

查看:80
本文介绍了无法隐式转换List< double>' “加倍”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续抛出,这部分代码出了什么问题,当我想返回单元格时,我收到此错误
无法将类型'System.Collections.Generic.List'隐式转换为'double':

Keeps throwing, what is wrong in this part of my code, when I want to return cells I receive this error Cannot implicitly convert type 'System.Collections.Generic.List' to '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>

It is hard to say for certain without seeing your entire function but my guess would be that you have the return type of your function set to double instead of List<double>. This would cause the error you are seeing.

确认正在查看您的编辑,这是您的问题。将函数的返回类型更改为 List< double> ,您将可以使用!您的代码应如下所示:

Confirmed looking at your edit that this is your problem. Change the return type of your function to List<double> and you will be good to go! Your code should look like this:

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;

    }

这篇关于无法隐式转换List&lt; double&gt;' “加倍”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆