2013-04-09 100 views
0

我有一个使用通用对象的类。通用对象需要实现IDisposable接口。 Class还需要实现IDisposable。实现接口的类和genric对象

public class MyGenericClass<T> where T : IDisposable 

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

回答

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

我试图MyGenericClass :IDisposable的:其中T:IDisposable接口。感谢你的回答, – 2013-04-09 19:40:45

2

是的,它是可能的:

公共类MyGenericClass:IDisposable的其中T:IDisposable的