>
>A class that implements IDisposable indicates to anything concerned that it should call Dispose(). This is, essentially, how the compiler translates the presence of a 'Using' block - if the created class implements IDisposable then it will automatically call Dispose() on that class at the end of the block.>
>And, in fact, it should be noted that if a class does not implement IDisposable, then you can't even have it in a using statement, you'll get a compiler error.
True.
But, TBH, I had the impression that that was *not* the case - I thought that you could wrap any class in a using block and that the check for IDisposable was made at run time - i.e. Dispose() was called on classes that implemented it and ignored if they did not.
No idea *why* I thought that though :-}
OTOneH implementing it that way would not have caused problems at runtime ; OTOH catching it at compile time avoids having the compiler generate unneeded code.
Another thing I only realized recently: within the same using block although you can instantiate multiple objects of the same type you cannot do so for different types. eg:
using (SomeClass s1 = new SomeClass(), s2 = new SomeClass()){}
using(SomeClass s1 = new SomeClass(), SomeOtherClass s2 = new SomeOtherClass()){}
Don't know why that restriction was neccessary....