c# - Explicit Conversion to IDisposable -


i using xmlreader , xmlwriter object needed work on strings inside try...catch blocks.

i know using notation using (xmlreader newreader = xmlreader.create(...)) prefered syntax, don't appending finally blocks , executing newreader.close(); , newwriter.close();.

however, code analysis complaining these objects aren't being disposed, forcing me somehow call dispose() method.

the problem in these classes dispose() method implemented explicitly, have use ((idisposable)(newreader)).dispose(); , ((idisposable)(newwriter)).dispose();.

are there drawbacks technique?

the c# using statement call dispose you. roughtly translates following:

xmlreader newreader = xmlreader.create(...); try {    // stuff on newreader  } {     ((idisposable)newreader).dispose(); } 

so wrapping in finally youself doesn't add value. although close , dispose equivalent, not case. because of fxcop right, should call dispose , when (or let using statement this), there no reason call close manually.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -