错误CS0029无法隐含转换System.Collections.Generic.List,返回不起作用

时间:2017-11-13 03:47:56

标签: c#

我的回复无效,错误CS0029暗示:

System.Collections.Generic.List<namesolution>namesolution 我如何让我的回归工作?

这是我的代码:

    [Route("/getVeiculos")]
    public VeiculoModel getVeiculos()
    {
        List<VeiculoModel> list = new List<VeiculoModel>();            
        list.Add( new VeiculoModel {
            idVeiculo = 1,
            corVeiculo = "Verde",
            marcaVeiculo = "Volks",
            modeloVeiculo = "UP!",
            placaVeiculo = "AAA-8754"

        });

        list.Add(new VeiculoModel
        {
            idVeiculo = 2,
            corVeiculo = "Azul",
            marcaVeiculo = "Volks",
            modeloVeiculo = "Fusca",
            placaVeiculo = "CDV-8754"
        });

        return list;   
    }
enter code here

1 个答案:

答案 0 :(得分:1)

您的方法getVeiculos()签名表示您正在尝试返回VeiculoModel类型的单个实例,但实现返回VeiculoModel列表。假设实现正确,请将方法签名更新为:

public List<VeiculoModel> getVeiculos()
{
    // implementation...
}