无法隐式转换类型System.Collections.Generic.IList System.Collections.Generic.List

use*_*828 1 c# generics list

基本上我正在将SQL数据表转换为我可以成功完成的通用列表.但我无法弄清楚如何返回列表对象.我得到一个错误,说是一个变体 - 无法隐式转换类型System.Collections.Generic.IList到System.Collections.Generic.List

将List作为类型List返回的正确方法是什么?

public List<MyObject> GetAllMyObjects()
{
    String command = "select * from names ";
    DataTable tableResult = DataTableToList.ExecuteDataTable(command, CommandType.Text, null,connectionString);

    IList<MyObject> theList = DataTableToList.ConvertTo<MyObject>(tableResult);

    return // I’m not sure how to return theList here...
}
Run Code Online (Sandbox Code Playgroud)

Dav*_*ych 7

打电话ToList给你的theList对象.

return theList.ToList();
Run Code Online (Sandbox Code Playgroud)