给定两个这样的接口:
public interface MyInterface1 : IDisposable
{
void DoSomething();
}
public interface MyInterface2 : IDisposable
{
void DoSomethingElse();
}
...和这样的实现类:
public class MyClass : IMyInterface1, IMyInterface2
{
public void DoSomething() { Console.WriteLine("I'm doing something..."); }
public void DoSomethingElse() { Console.WriteLine("I'm doing something else..."); }
public void Dispose() { Console.WriteLine("Bye bye!"); }
}
...我假设以下代码片段应该编译:
class Program
{
public static void Main(string[] args)
{
using (MyInterface1 myInterface = new MyClass()) {
myInterface.DoSomething();
}
}
}
...相反,我总是收到以下错误消息:
Error 1 'IMyInterface1': type used in a using statement must be implicitly convertible to 'System.IDisposable'
任何想法?谢谢。