The slap upside the head to remember to read my Intellisense was what I
needed but I thought I read while searching the web that one intended use of
the using statement will dispose automatically as an intentional response to
such circumstance such as the example you mention. And are you using the
term function to refer to a method of a class?
"Mark Tolonen" <M8********@mailinator.comwrote in message
news:sd******************************@comcast.com. ..
If you are unsure that a class implements IDisposable (perhaps the class
name was passed to a function and created dynamically), the construction:
using(instance as IDisposable)
{
.
.
.
}
will call Dispose on instance only if the method exists.
-Mark
"KH" <KH@discussions.microsoft.comwrote in message
news:E5**********************************@microsof t.com...
>Use the documentation - MSDN - to see if a type implements IDisposable -
it
will be in the type signature, e.g:
public class SomeType : IDisposable;
Or you could type some code in VS and see if Dispose() is in the
intellisense list.
The using statement compiles to a try/finally block under the covers so I
doubt it's any more efficient than writing the try/finally yourself.
HTH
"Hillbilly" wrote:
>>MSDN Remarks [1] "as a rule" the using statement should be used when
instantiating objects which inherit IDisposable. Other than the obvious
unmanaged objects like the file system example, fonts and the database
how
else may it be determined which classes and their objects inherit
IDisposable?
And the remarks imply the using statement is a different and perhaps
more
efficient way to use objects than try-catch-finally?
[1] http://msdn.microsoft.com/en-us/library/yh598w02.aspx