MemoryStream in Using Statement - Do I need to call close()

Total Post:110

Points:774
C# 
C#
 1378  View(s)
Ratings:
Rate this:

When using a memory stream in a using statement do I need to call close? For instance is ms.Close() needed here?

  using (MemoryStream ms = new MemoryStream(byteArray)) 
    { 
      // stuff
      ms.Close();
    }
  1. Post:412

    Points:2888
    Re: MemoryStream in Using Statement - Do I need to call close()

    Hi jayden,

    No, you don't need. It will be called by the .Dispose() method which is automatically called:

    using (MemoryStream ms = new MemoryStream(byteArray))

        // stuff
    }

      Modified On Apr-04-2018 03:55:54 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!