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]'

4

1 に答える 1

2

これは、GetTable メソッドがパラメーター化されているためだと思います。次のように定義してみてください。

public List<TEntity> GetTable () {...}
于 2012-07-08T13:33:21.073 に答える