2013-04-09 101 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的