首页 文章

通用列表的转换问题

提问于
浏览
0

在下面的代码编译错误发生但我不明白为什么 .

class RealMock<TEntity> : DataContext
{
    public RealMock():base("")
    {

    }

    public List<TEntity> inMemoryDataStore = new List<TEntity>();
    public List<TEntity> GetTable<TEntity>() where TEntity : class
    {
        return inMemoryDataStore;  //Compilation error       
    }
}

无法将类型'System.Collections.Generic.List [c:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.0 \ mscorlib.dll]'隐式转换为'System.Collections.Generic.List [ c:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.0 \ mscorlib.dll]'

1 回答

  • 2

    我相信这是因为参数化的GetTable方法,尝试将其定义为

    public List<TEntity> GetTable () {...}
    

相关问题