类和通用对象都实现接口

时间:2013-04-09 13:46:20

标签: c# generics interface

我有一个使用通用对象的类。通用对象需要实现IDisposable接口。类也需要实现IDisposable。

public class MyGenericClass<T> where T : IDisposable

现在在这个Generic对象实现接口,但类没有。是否有可能实现接口?如果是的话。

2 个答案:

答案 0 :(得分:4)

public class MyGenericClass<T> : IDisposable
    where T : IDisposable
{
    public void Dispose()
    {
        throw new NotImplementedException();
    }
}

答案 1 :(得分:2)

是的,有可能:

  

public class MyGenericClass:IDisposable,其中T:IDisposable

相关问题