Often is it necessary to have a system with an optimized memory management. If you use local objects, for example StringReader, the created object must be disposed at the end of the method. You have two ways to do this:

  1. Dispose() the StringReader object
  2. Use the using statement as follows:





Here after the using statement, the StringReader object will be destroyed after the curly brackets. The advantage of this method to the use of Dispose() is that if a exception occurs the StringReader object will be destroyed anyway. When just using Dispose() it is not guaranteed that the object will be disposed.

For more information: MSDN Link

c#: using statement for IDisposable interface
Tagged on:

Leave a Reply


Get every new post on this blog delivered to your Inbox.

Join other followers:

Welcome Damir Kusar

Log in

Lost your password?
%d bloggers like this: