What is the relationship between the using keyword and the IDisposable interface?

后端 未结 7 542
栀梦
栀梦 2020-12-10 18:38

If I am using the using keyword, do I still have to implement IDisposable?

7条回答
  •  情深已故
    2020-12-10 18:50

    You must implement IDisposable to use using. If you try to use using() on a type that does not implement IDisposable you get the following compile time error:

    error CS1674: 'SomeType': type used in a using statement must be implicitly convertible to 'System.IDisposable'
    

提交回复
热议问题